-
Notifications
You must be signed in to change notification settings - Fork 0
/
turin.asm
143 lines (133 loc) · 2.21 KB
/
turin.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
; TurinBot Compiled Assembly
section .data
;Current Register
register db 0
;Registers
registers db 0, 0, 0, 0, 0, 0, 0
; String readQuestion
readQuestion: db 'Type in read answer (y/n):',10
readQuestionLen: equ $-readQuestion
; String hello
hello: db 'Running Code',10
helloLen: equ $-hello
; String front
front: db 'robot: front',10
frontLen: equ $-front
; String left
left: db 'robot: left',10
leftLen: equ $-left
; String right
right: db 'robot: right',10
rightLen: equ $-right
; String beep
beep: db 'robot: beep',10
beepLen: equ $-beep
section .bss
buf resb 1 ; 1000-byte buffer (in data section)
section .text
global _start
robot_front:
;function begin
;Print variable front
mov eax,4
mov ebx,1
mov ecx,front
mov edx,frontLen
int 80h
ret
;end
robot_left:
;function begin
;Print variable left
mov eax,4
mov ebx,1
mov ecx,left
mov edx,leftLen
int 80h
ret
;end
robot_right:
;function begin
;Print variable right
mov eax,4
mov ebx,1
mov ecx,right
mov edx,rightLen
int 80h
ret
;end
robot_beep:
;function begin
;Print variable beep
mov eax,4
mov ebx,1
mov ecx,beep
mov edx,beepLen
int 80h
ret
;end
read:
;function begin
;Print variable readQuestion
mov eax,4
mov ebx,1
mov ecx,readQuestion
mov edx,readQuestionLen
int 80h
mov edx,1
mov ecx,buf ;Save user input to buffer.
mov ebx,0 ;From stdin
mov eax,3 ;sys_read. Read what user inputs
int 80h
mov eax, registers
add eax, [register]
mov [eax], byte 1
mov cl, 'y'
cmp [buf],cl
je read_FINALLY
mov eax, registers
add eax, [register]
mov [eax], byte 0
read_FINALLY:
ret
;end
_start:
;Print variable hello
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,helloLen
int 80h
; nop
;goToBookmark:PURPLE
JMP SHORT PURPLE
;saveBookmark:RED
RED:
;front
call robot_front
;goToBookmark:PURPLE
JMP SHORT PURPLE
;saveBookmark:BLUE
BLUE:
;right
call robot_right
;goToBookmark:PURPLE
JMP SHORT PURPLE
;saveBookmark:PURPLE
PURPLE:
;readFromSensor
call read
;jumpTrue
mov eax, registers
add eax, [register]
cmp [eax], byte 0
jne jumpTrue_25
;goToBookmark:BLUE
JMP SHORT BLUE
;jumpTrue callback
jumpTrue_25:
;goToBookmark:RED
JMP SHORT RED
; nop
mov eax, 1 ;sys exit
int 0x80