Skip to content

Commit 4cb3d6a

Browse files
authored
Merge branch 'master' into master
2 parents 7dec529 + f079291 commit 4cb3d6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4833
-209
lines changed

4 Digit Number Combinations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ def FourDigitCombinations():
33
numbers=[]
44
for code in range(10000):
55
code=str(code).zfill(4)
6-
print code,
6+
print(code)
77
numbers.append(code)
8+
9+
# Same as above but more pythonic
10+
def oneLineCombinations():
11+
numbers = list(map(lambda x: str(x).zfill(4), [i for i in range(10000)]))
12+
print(numbers)

Assembler/GUIDE.txt

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Guide for Python-Assembler
2+
3+
### Register
4+
5+
In this programming language you can use four registers.
6+
* eax
7+
* ebx
8+
* ecx
9+
* edx
10+
11+
The register **eax** will be standard use for multiplication and division.
12+
Commands for arithmetic are:
13+
14+
* add p0, p1
15+
* sub p0, p1
16+
* mul [register]
17+
* div [register]
18+
19+
p0 and p1 stands for parameter. p0 must be a register, p1 can be a register or constant.
20+
The commands **mul** and **div** standard use eax. For instance:
21+
22+
```
23+
mov ecx, 56
24+
sub ecx, 10
25+
mov eax, 4
26+
int 0x80
27+
28+
```
29+
30+
* The first line move the number 56 into register ecx.
31+
* The second line subtract 10 from the ecx register.
32+
* The third line move the number 4 into the eax register. This is for the print-function.
33+
* The fourt line call interrupt 0x80, thus the result will print onto console.
34+
* The fifth line is a new line. This is important.
35+
36+
**Important: close each line with a newline!**
37+
38+
### System-Functions
39+
40+
With the interrupt 0x80 you can use some functionality in your program.
41+
42+
EAX | Function
43+
---- | ---------
44+
1 | exit program. error code in ebx
45+
3 | read input. onto ecx (only float)
46+
4 | output onto console. print content in ecx
47+
48+
EAX stands for the register eax
49+
50+
### Variables
51+
52+
Variables begin with a $ or written in uppercase.
53+
54+
For instance:
55+
56+
```
57+
58+
; variables
59+
VAR1 db 56
60+
$var1 db 10
61+
62+
mov ecx, VAR1
63+
mov ebx, $var1
64+
sub ecx, ebx
65+
mov eax, 4
66+
int 0x80
67+
68+
```
69+
70+
**Important: The arithmetic commands (add, sub) works only with registers or constans.
71+
Therefore we must use the register ebx as a placeholder, above.**
72+
73+
74+
Result of code, above.
75+
76+
```
77+
46
78+
```
79+
80+
### Comments
81+
82+
Comments begin with ; and ends with a newline.
83+
We noticed a comment, above.
84+
85+
### Push and Pop
86+
87+
Sometimes we must save the content of a register, against losing of data.
88+
Therefor we use the push and pop command.
89+
90+
```
91+
push eax
92+
93+
```
94+
95+
This line will push the content of register eax onto the stack.
96+
97+
```
98+
pop ecx
99+
100+
```
101+
102+
This line will pop the content of the top of the stack onto the ecx register.
103+
104+
```
105+
push [register]
106+
pop [register]
107+
108+
```
109+
110+
### Jumps
111+
112+
With the command **cmp** we can compare two register.
113+
114+
```
115+
cmp r0, r1
116+
je l1
117+
jmp l2
118+
119+
```
120+
121+
Are the two register equal? The the command **je** is actively and jumps to label **l1**
122+
Otherwise the command **jmp** is actively and jumps to label **l2**
123+
124+
#### Labels
125+
126+
For instance
127+
128+
```
129+
l1:
130+
131+
```
132+
133+
is a label.
134+
Labels begin with a **l** and contains numbers.
135+
For instance l1, l2 etc ...
136+
137+
To set a label you must end with a colon.
138+
If you use a label in the jump commands, then avoid the colon at the end.
139+
140+
### Subprograms
141+
142+
```
143+
mov ecx, 5
144+
145+
call _double
146+
call _cube
147+
call _inc
148+
149+
mov eax, 4
150+
int 0x80
151+
mov eax, 1
152+
mov ebx, 0
153+
int 0x80
154+
155+
156+
157+
_double:
158+
add ecx, ecx
159+
ret
160+
161+
_cube:
162+
push eax
163+
mov eax, ecx
164+
add ecx, eax
165+
add ecx, eax
166+
pop eax
167+
ret
168+
169+
_inc:
170+
add ecx, 1
171+
ret
172+
173+
```
174+
175+
A subprogram label begins with a **_** and ends with a colon. See above.
176+
177+
178+
If you call the subprogram you must avoid the colon.
179+
180+
``` call _subprogramName
181+
```
182+
183+
**Important:** Each subprogram must end with the **ret** command.

Assembler/README.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Python-Assembler
2+
3+
This program is a simple assembler-like (intel-syntax) interpreter language. The program is written in python 2.
4+
To start the program you will type
5+
6+
``` python assembler.py code.txt ```
7+
8+
9+
After you type 'enter' the program will interpret the source-code in 'code.txt'
10+
You can use many texfiles as input. These will be interpret one by one.
11+
12+
You find some examples in the directory 'examples'.
13+
14+
For instance
15+
16+
```
17+
$msg db "hello world"
18+
19+
mov ecx, $msg
20+
mov eax, 4
21+
int 0x80
22+
mov eax, 1
23+
mov ebx, 0
24+
int 0x80
25+
```
26+
27+
Will print onto console
28+
29+
```
30+
hello world
31+
END PROGRAM
32+
```
33+
34+
**You find a guide in GUIDE.md**
35+

0 commit comments

Comments
 (0)