Compare commits
3 Commits
22f1cae833
...
testing
Author | SHA1 | Date | |
---|---|---|---|
33175e2c19
|
|||
5685ac6e67
|
|||
3360f1976c
|
@@ -4,14 +4,36 @@
|
|||||||
; Run with: ./helloworld
|
; Run with: ./helloworld
|
||||||
|
|
||||||
SECTION .data
|
SECTION .data
|
||||||
msg db 'Hello World!', 0Ah ; assign msg variable with your message string
|
msg db 'Hello, brave new world!', 0Ah ; assign msg variable with your message string
|
||||||
|
|
||||||
SECTION .text
|
SECTION .text
|
||||||
global _start
|
global _start
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
mov edx, 13 ; number of bytes to write - one for each letter plus 0Ah (line feed character)
|
mov eax, msg
|
||||||
mov ecx, msg ; move the memory address of our message string into ecx
|
call strlen
|
||||||
mov ebx, 1 ; write to the STDOUT file
|
|
||||||
mov eax, 4 ; invoke SYS_WRITE (kernel opcode 4)
|
mov edx, eax ; our function leaves the result in EAX
|
||||||
|
mov ecx, msg
|
||||||
|
mov ebx, 1 ; STDOUT
|
||||||
|
mov eax, 4 ; SYS_WRITE
|
||||||
int 80h
|
int 80h
|
||||||
|
|
||||||
|
mov ebx, 0 ; return 0
|
||||||
|
mov eax, 1 ; SYS_EXIT
|
||||||
|
int 80h
|
||||||
|
|
||||||
|
strlen:
|
||||||
|
push ebx ; preserve EBX while we use in this function
|
||||||
|
mov ebx, eax ; move the address in EAX into EBX
|
||||||
|
|
||||||
|
nextchar:
|
||||||
|
cmp byte [eax], 0 ; compare the byte pointed to by EAX at this address against zero (Zero is an end of string delimiter)
|
||||||
|
jz finished ; jump (if the zero flagged has been set) to the point in the code labeled 'finished'
|
||||||
|
inc eax ; increment the address in EAX by one byte (if the zero flagged has NOT been set)
|
||||||
|
jmp nextchar ; jump to the point in the code labeled 'nextchar'
|
||||||
|
|
||||||
|
finished:
|
||||||
|
sub eax, ebx
|
||||||
|
pop ebx
|
||||||
|
ret
|
||||||
|
Reference in New Issue
Block a user