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
|
global _start
struc ellipse
major: resd 1
minor: resd 1
area: resd 1
circumference: resd 1
eccentricity: resd 1
endstruc
section .data
e:
istruc ellipse
at major, dd 0
at minor, dd 0
at area, dd 0
at circumference, dd 0
at eccentricity, dd 0
iend
section .rodata noexec nowrite align=4
pi: dd 3.141592653589793238462
section .text
_start:
finit
mov ebx, 100
; .repeat:
lea edi, [rbx + 0]
call print_uint32
; dec ebx
; jge .repeat
xor edi, edi
mov eax, 231
syscall
; mov rax, 60
; mov rdi, 0
; syscall
; void print_uint32(uint32_t edi)
;
; https://stackoverflow.com/questions/13166064/how-do-i-print-an-integer-in-assembly-level-programming-without-printf-from-the
print_uint32:
mov eax, edi
mov ecx, 0xa
push rcx
mov rsi, rsp
sub rsp, 16
.to_ascii_digit:
xor edx, edx
div ecx
add edx, '0'
dec rsi
mov [rsi], dl
test eax, eax
jnz .to_ascii_digit
mov eax, 1
mov edi, 1
lea edx, [rsp + 16 + 1]
sub edx, esi
syscall
add rsp, 24
ret
|