assemblytutorials
assemblytutorials copied to clipboard
Lesdon #5 - function sprint changes eax
;------------------------------------------
; void sprint(String message)
; String printing function
sprint:
push edx
push ecx
push ebx
push eax
call slen
mov edx, eax
pop eax
mov ecx, eax
mov ebx, 1
mov eax, 4
int 80h
pop ebx
pop ecx
pop edx
ret
Function sprint changes EAX register by doing
mov eax, 4
but doesn't restore it after that.
I suggest to add one more
; after pop eax
push eax
and then
pop eax
; before pop ebx
Hey there!
Thanks for getting in touch.
I agree, it is a little bit odd to push something onto the stack and then not replace it at the end of the function. However, my thinking at time was to allow the developer to read the return value from sys_write
(which could return -1 to indicate an error).
Responsibility then was left to the developer to restore the original value from the stack if they required it.
https://man7.org/linux/man-pages/man2/write.2.html