-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubroutines.asm
35 lines (27 loc) · 1.09 KB
/
subroutines.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
SECTION .data
msg db 'Hello, brave new world!', 0Ah
SECTION .text
global _start
_start:
mov eax, msg ; move the address of our message string into EAX
call strlen ; call our function to calculate the length of the string
mov edx, eax ; our function leaves the result in EAX
mov ecx, msg ; this is all the same as before
mov ebx, 1
mov eax, 4
int 80h
mov ebx, 0
mov eax, 1
int 80h
strlen: ; this is our first function declaration
push ebx ; push the value in EBX onto the stack to preserve it while we use EBX in this function
mov ebx, eax ; move the address in EAX into EBX (Both point to the same segment in memory)
nextchar: ; this is the same as lesson3
cmp byte [eax], 0
jz finished
inc eax
jmp nextchar
finished:
sub eax, ebx
pop ebx ; pop the value on the stack back into EBX
ret ; return to where the function was called