; linux assembly procedures for nasm! i use these for debugging sometimes. SECTION .data testval: dd 31337 SECTION .text global main main: push testval push dword 4 call prnbin push dword [testval] call prnint mov ebx, 0 mov eax, 1 int 0x80 ; prnbin ; ############ ; push PTR ; push SIZE ; call prnbin ; ############ ; prints the binary representation of SIZE bytes from memory at PTR ; in reverse order (because little endian sucks) ; ; doesn't clobber registers (yay) SECTION .data prnbin_field: db 0,0,0,0,0,0,0,0,32 SECTION .text prnbin: pushad pushfd mov ebp, esp mov ebx, [ebp+44] mov esi, [ebp+40] prnbin_loop0: mov dl, 128 mov eax, 0 prnbin_loop1: mov dh, '0' test [ebx+esi-1], dl jz prnbin_if0 inc dh prnbin_if0: mov [prnbin_field+eax], dh inc eax shr dl, 1 jnz prnbin_loop1 push ebx mov eax, 4 mov ebx, 1 mov ecx, prnbin_field mov edx, 9 int 0x80 pop ebx dec esi jnz prnbin_loop0 popfd popad ret 8 ; prnint ; ############## ; push dword [VAL] ; call prnint ; ############## ; prints the unsigned integer value of VAL, followed by a newline. ; this is not the most efficient way to do this (or even close) so don't ; use it for anything important. for something important you'll probably ; want some sort of double-dabble implementation, or just use printf. ; ; doesn't clobber registers (yay) SECTION .data prnint_field: db "xxxxxxxxxx",10 SECTION .text prnint: pushad pushfd mov ebp, esp mov eax, [ebp+40] mov ebx, prnint_field mov ecx, 10 mov esi, 9 prnint_loop0: xor edx, edx div ecx add dl, 48 mov [ebx+esi], dl dec esi cmp eax, 0 jne prnint_loop0 mov eax, 4 lea ecx, [ebx+esi+1] mov ebx, 1 mov edx, 10 sub edx, esi int 0x80 popfd popad ret 4