-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.asm
More file actions
43 lines (33 loc) · 1.69 KB
/
print.asm
File metadata and controls
43 lines (33 loc) · 1.69 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
section .data
message1 db "Hello, World!", 0xA ; First string to print with a newline
len1 equ $ - message1 ; Length of the first string
message2 db "Goodbye, World!", 0xA ; Second string to print with a newline
len2 equ $ - message2 ; Length of the second string
section .bss
section .text
global _start
_start:
; Call print with the first message
push len1 ; Push the length of the first message
push message1 ; Push the address of the first message
call print ; Call print subroutine
add esp, 8 ; Clean up the stack (2 * 4 bytes)
; Call print with the second message
push len2 ; Push the length of the second message
push message2 ; Push the address of the second message
call print ; Call print subroutine
add esp, 8 ; Clean up the stack (2 * 4 bytes)
; Exit the program
mov eax, 1 ; syscall number for sys_exit
xor ebx, ebx ; exit code 0
int 0x80 ; make syscall to exit
print:
; Arguments:
; [esp+4] = length of the string
; [esp] = address of the string
mov eax, 4 ; syscall number for sys_write
mov ebx, 1 ; file descriptor 1 (stdout)
mov ecx, [esp+4] ; load the address of the string
mov edx, [esp+8] ; load the length of the string
int 0x80 ; make syscall to write
ret ; return from subroutine