-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsum.asm
48 lines (43 loc) · 889 Bytes
/
sum.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
;initialised data section
section .data
; Define constants
num1: equ 100
num2: equ 50
; http://geekswithblogs.net/MarkPearl/archive/2011/04/13/more-nasm.aspx
msg: db "Sum is correct", 10
;;
;; program code
;;
section .text
global _start
;; entry point
_start:
; get sum of num1 and num2
mov rax, num1
mov rbx, num2
add rax, rbx
; compare rax with correct sum - 150
cmp rax, 150
; if rax is not 150 go to exit
jne .exit
; if rax is 150 print msg
jmp .rightSum
; Print message that sum is correct
.rightSum:
;; write syscall
mov rax, 1
;; file descritor, standard output
mov rdi, 1
;; message address
mov rsi, msg
;; length of message
mov rdx, 15
;; call write syscall
syscall
; exit from program
jmp .exit
; exit procedure
.exit:
mov rax, 60
mov rdi, 0
syscall