-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.asm
More file actions
63 lines (49 loc) · 1.05 KB
/
basic.asm
File metadata and controls
63 lines (49 loc) · 1.05 KB
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
section .data
msg db "Result: ", 0
section .bss
buffer resb 10
section .text
global _start
_start:
; Example: just print something
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, msg
mov edx, 8
int 0x80
; Exit
mov eax, 1
xor ebx, ebx
int 0x80
section .text
global _start
_start:
; Load numbers into registers
mov eax, 1000
mov ebx, 25
add eax, ebx
mov al, [num1] ; AL = 10
mov bl, [num2] ; BL = 4
fld dword [num1] ; load float
fld dword [num2]
fadd ; add
fstp dword [result]
; Addition
add al, bl ; AL = AL + BL (10 + 4 = 14)
; Subtraction
sub al, bl ; AL = AL - BL (14 - 4 = 10)
; Multiply
mov eax, 10
mov ebx, 4
mul ebx ; EAX = 10 * 4 = 40
; Division
mov eax, 40
mov ebx, 4
div ebx ; EAX = 10, EDX = remainder
cmp eax, ebx
jg greater
jl lesser
; Exit program
mov eax, 1 ; sys_exit
xor ebx, ebx ; exit code 0
int 0x80