Skip to content

Commit 31a48b3

Browse files
Merge branch 'master' into test
2 parents dbaf50c + 189efcc commit 31a48b3

File tree

201 files changed

+13783
-538
lines changed

Some content is hidden

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

201 files changed

+13783
-538
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
*.pyc

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
language: python
2+
cache: pip
3+
python:
4+
- 2.7
5+
- 3.6
6+
#- nightly
7+
#- pypy
8+
#- pypy3
9+
matrix:
10+
allow_failures:
11+
- python: nightly
12+
- python: pypy
13+
- python: pypy3
14+
install:
15+
#- pip install -r requirements.txt
16+
- pip install flake8 # pytest # add another testing frameworks later
17+
before_script:
18+
# stop the build if there are Python syntax errors or undefined names
19+
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
20+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
21+
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
22+
script:
23+
- true # pytest --capture=sys # add other tests here
24+
notifications:
25+
on_success: change
26+
on_failure: change # `always` will be the setting once code changes slow down

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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Python-Assembler
2+
#WE NEED A FREE T-SHIRT
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 hit '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+
**Refer to GUIDE.txt to read a guide**

0 commit comments

Comments
 (0)