Last active
October 29, 2017 03:52
-
-
Save dstein64/eda0edbdce6c83f8495bcd057daad57c to your computer and use it in GitHub Desktop.
Helper macro and function for printenv.s and echo.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section .text | |
# ************************************ | |
# * print macro | |
# * Caller is responsible for setting | |
# * %ecx and %edx, and saving %eax and | |
# * %ebx if necessary. | |
# ************************************ | |
.macro print | |
movl $4, %eax | |
movl $1, %ebx | |
int $0x80 | |
.endm | |
.section .text | |
# ************************************ | |
# * int strlen(char* str); | |
# * Returns the length of a string. | |
# ************************************ | |
.type strlen, @function | |
strlen: | |
pushl %ebp | |
movl %esp, %ebp | |
movl $0, %eax # Index | |
movl 8(%ebp), %ecx # Address of str | |
strlen_loop: | |
movb (%ecx,%eax,1), %dl # Current char | |
cmpb $0, %dl | |
je strlen_end | |
incl %eax | |
jmp strlen_loop | |
strlen_end: | |
movl %ebp, %esp | |
popl %ebp | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment