projects
/
libmalice.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
20ac18e
)
Don't save eax/ecx/edx: Can clobber them in IA-32.
author
norly
<ny-git@enpas.org>
Sun, 13 Jan 2013 18:21:01 +0000
(18:21 +0000)
committer
norly
<ny-git@enpas.org>
Sun, 13 Jan 2013 18:25:43 +0000
(18:25 +0000)
libmalice.asm
patch
|
blob
|
history
diff --git
a/libmalice.asm
b/libmalice.asm
index adb9907d47d9f79ab6fc85fe913fb924a3ff89d6..6e05076187e3c7b91185b045ccc6fd3b49b6ec2a 100644
(file)
--- a/
libmalice.asm
+++ b/
libmalice.asm
@@
-39,21
+39,18
@@
jmp _start_end ; poor man's exception handling
global lmPrintChar
lmPrintChar: ; void lmPrintChar(int chr)
global lmPrintChar
lmPrintChar: ; void lmPrintChar(int chr)
-
push
eax ; will be: syscall number
+
;
eax ; will be: syscall number
push ebx ; will be: stdout fd
push ebx ; will be: stdout fd
-
push
ecx ; will be: character start address
-
push
edx ; will be: character counter
+
;
ecx ; will be: character start address
+
;
edx ; will be: character counter
mov edx, 1 ; print one char
mov edx, 1 ; print one char
-lea ecx, [esp+
20]
; address of the char
+lea ecx, [esp+
8]
; address of the char
mov ebx, 1 ; stdout fd
mov eax, 4 ; write()
int 0x80
mov ebx, 1 ; stdout fd
mov eax, 4 ; write()
int 0x80
-pop edx
-pop ecx
pop ebx
pop ebx
-pop eax
ret
ret
@@
-64,13
+61,13
@@
ret
global lmPrintString
lmPrintString: ; void lmPrintString(char *string)
global lmPrintString
lmPrintString: ; void lmPrintString(char *string)
-
push
eax ; will be: syscall number
+
;
eax ; will be: syscall number
push ebx ; will be: stdout fd
push ebx ; will be: stdout fd
-
push
ecx ; will be: character start address
-
push
edx ; will be: character counter
+
;
ecx ; will be: character start address
+
;
edx ; will be: character counter
mov eax, 0 ; prepare for holding a char
mov eax, 0 ; prepare for holding a char
-mov ecx, [esp+
20]
; string start address
+mov ecx, [esp+
8]
; string start address
mov edx, -1 ; init char counter to 0
_print_string_loop:
mov edx, -1 ; init char counter to 0
_print_string_loop:
@@
-83,10
+80,7
@@
mov ebx, 1 ; stdout fd
mov eax, 4 ; write()
int 0x80
mov eax, 4 ; write()
int 0x80
-pop edx
-pop ecx
pop ebx
pop ebx
-pop eax
ret
ret
@@
-97,11
+91,11
@@
ret
global lmPrintInt32s
lmPrintInt32s: ; void lmPrintInt(int num)
global lmPrintInt32s
lmPrintInt32s: ; void lmPrintInt(int num)
-
push
eax ; will be: dividend
+
;
eax ; will be: dividend
push ebx ; will be: divisor
push ebx ; will be: divisor
-
push
ecx ; will be: character start address
-
push
edx ; will be: character counter
-mov eax, [esp+
20]
; load num
+
;
ecx ; will be: character start address
+
;
edx ; will be: character counter
+mov eax, [esp+
8]
; load num
sub esp, 12 ; make space for converted integer
lea ecx, [esp+11] ; string offset counter, start at lastchar+1
; so writing ends at 10 and char 11 is reserved
sub esp, 12 ; make space for converted integer
lea ecx, [esp+11] ; string offset counter, start at lastchar+1
; so writing ends at 10 and char 11 is reserved
@@
-121,7
+115,7
@@
_print_int_loop:
test eax, eax
jne _print_int_loop
test eax, eax
jne _print_int_loop
-cmp [esp+
32
], dword 0 ; check for negative number
+cmp [esp+
20
], dword 0 ; check for negative number
jge _print_int_end ; skip for positive
dec ecx
mov [ecx], byte '-' ; add - sign
jge _print_int_end ; skip for positive
dec ecx
mov [ecx], byte '-' ; add - sign
@@
-134,10
+128,7
@@
mov eax, 4 ; write()
int 0x80 ; let the number speak
add esp, 12
int 0x80 ; let the number speak
add esp, 12
-pop edx
-pop ecx
pop ebx
pop ebx
-pop eax
ret
ret
@@
-149,8
+140,6
@@
ret
global lmReadChar
lmReadChar: ; int lmReadChar(void)
push ebx
global lmReadChar
lmReadChar: ; int lmReadChar(void)
push ebx
-push ecx
-push edx
sub esp, 4 ; make room for character to be read
sub esp, 4 ; make room for character to be read
@@
-172,8
+161,6
@@
mov al, [esp]
_read_char_end:
add esp, 4
_read_char_end:
add esp, 4
-pop edx
-pop ecx
pop ebx
ret
pop ebx
ret
@@
-187,8
+174,6
@@
ret
global lmReadInt32s
lmReadInt32s: ; int lmReadInt(void)
push ebx
global lmReadInt32s
lmReadInt32s: ; int lmReadInt(void)
push ebx
-push ecx
-push edx
push esi ; negative number info
push edi ; actual number
push esi ; negative number info
push edi ; actual number
@@
-257,8
+242,6
@@
mov eax, edi ; Return value: The number read
add esp, 4
pop edi
pop esi
add esp, 4
pop edi
pop esi
-pop edx
-pop ecx
pop ebx
ret
pop ebx
ret