summer love lessons - renewing the knack for asm
i’ve only been slacking, eating and watching anime since summer started. this afternoon, i found the time to begin work on assemblifying a bash script i saw some days ago. the bash script has been modified already but it’s former function was simply a “for loop” wget to fetch a 0-22 page html version of a book - 1984. while i really didn’t achieve a boost in speed nor a significant cut in file size over the bash counterpart, the activity presented me a scenario where i had to do string and buffer manipulations in asm. also, i cheated, since i used extern printf print the strings. the program’s current size is 8.0 kilobytes which is double the size of the bash script. though i can pass the fault to gcc, linking of additional sections to produce the final elf object.
nothing much from this one really. again, some things are better off scripted. check her site out for even shorter suggestions. anyway, the program is complete now. here goes.
; miss godiane's wget sript assemblified
extern printf
global main
section .text
main
push ebp
mov ebp, esp
and esp, -0x10
mov ecx, (url2 - url1) ; construct website domain
mov esi, url1
mov edi, buf
cld
rep movsb
xor ecx, ecx ; initialize
_loop
push edi ; save offset address
push ecx ; save counter value
mov eax, ecx ; accumulator holds it now
mov cl, 0xa ; divisor value
div cl
test al, al ; two digit number?
jz _ones
add al, 0x30 ; deal with tens place
mov byte [edi], al
inc edi
_ones
add ah, 0x30 ; deal with ones place
mov byte [edi], ah
inc edi ; append html extension
mov ecx, (eurl - url2)
mov esi, url2
rep movsb
push st
call printf
pop edx ; clear the stack
mov byte [wget+13], 0x0
lea dword ebx, [wget]
mov dword [wget+14], ebx
lea dword ebx, [buf]
mov dword [wget+18], ebx
xor edx, edx
mov dword [wget+22], edx
mov eax, 0xb ; sys_execve
mov ebx, wget
lea ecx, [wget+14]
xor edx, edx
int 0x80
pop ecx ; restor counter value
pop edi ; restore offset address
inc ecx ; next html page please.
cmp ecx, 22 ; are we there yet?
jle _loop ; 'til 22.html only
_exit
xor eax, eax ; graceful exit
leave
ret
section .data
wget db '/usr/bin/wget stefanieNULL'
st db 'Getting part %d of 22 of 1984',0xa,0x0
url1 db 'http://www.george-orwell.org/1984/'
url2 db '.html',0x0
eurl
section .bss
buf resb 500
