-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidtermQ3.asm
145 lines (118 loc) · 2.11 KB
/
midtermQ3.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
144
145
;! gets a binary representation of a number prints out hex representation
%include "in_out.asm"
section .data
Msg db 'Hello World', 0
section .bss
s resq 1
sE resq 1
shiftc resq 1
section .text
global _start
convert:
xor rdx,rdx
convertLoop:
STD
lodsw
mov rbx, rax
mov rcx, [shiftc]
shiftrdx:
cmp rcx,0
JE shiftrdxExt
shl rdx,1
dec rcx
JMP shiftrdx
shiftrdxExt:
mov rcx, [shiftc]
shiftrax:
cmp rcx,0
JE shiftraxExt
shr rax,1
dec rcx
JMP shiftrax
shiftraxExt:
and rdx, 0x0F
add rax,rdx
and ax, 0x0F
mov rdx, rbx
cmp al, 9
JA convertLoopover10
add rax,'0'
call putc
JMP convertLoopcheck
convertLoopover10:
add rax, 55
call putc
JMP convertLoopcheck
convertLoopcheck:
cmp rsi, rdi
JGE convertLoop
convertExt:
ret
_start:
mov rax, rsp
sub rax, 2
mov [s], rax ;saving top of stack to [s] we store our string in stack
inputcloop1:
call getc
cmp al, 0xA
JE inputcloopExt
xor rbx,rbx
sub rax, 0x30; ourchar - '0'
add rbx,rax
mov rcx,3
inputcloop2:
call getc
cmp al,0xA
mov [shiftc],rcx
JE inputcloopExt
sub rax, 0x30; ourchar - '0'
shl rbx, 1
add rbx,rax
loop inputcloop2
mov [shiftc],rcx
cmp bx,0
JE inputcloop1
push bx
JMP inputloop1
inputcloopExt:
mov rcx, [shiftc]
shiftrbbbbb:
cmp rcx,0
JE shiftrbbbbbe
shl rbx,1
dec rcx
JMP shiftrbbbbb
shiftrbbbbbe:
push bx
JMP inputloopExt
inputloop1:
call getc
cmp al, 0xA
JE inputloopExt
xor rbx,rbx
sub rax, 0x30; ourchar - '0'
add rbx,rax
mov rcx,3
inputloop2:
call getc
cmp al,0xA
mov [shiftc],rcx
JE inputcloopExt
sub rax, 0x30; ourchar - '0'
shl rbx, 1
add rbx,rax
loop inputloop2
mov [shiftc],rcx
push bx
JMP inputloop1
inputloopExt:
; mov rax, [shiftc]
; call writeNum
mov rsi, [s];start of string
mov [sE], rsp
mov rdi, rsp;end of string
call convert
Exit:
mov rax, 1
mov rbx, 0
int 0x80