; regeax.asm for regeaxing various things ; Assemble: nasm -f elf -l regeax.lst regeax.asm ; Link: gcc -o regeax regeax.o ; Run: regeax ; Output: ; eax=789ABCDE ; eax=789A1234 loading a part of a register, leaves rest same ; eax=789A05DE ; eax=789ABC06 global main ; the standard gcc entry point extern printf ; the C function, to be called section .data ; Data section, initialized variables a: dd 5 ; int a=5; fmt: db "eax=%X",10,0 ; The printf format, "\n",'0' section .text ; Code section. main: ; the program label for the entry point push ebp ; set up stack frame mov ebp,esp push ebx mov eax,0x789abcde push eax push dword fmt ; address of ctrl string call printf ; Call C function add esp,8 ; pop stack, 2 push times 4 bytes mov eax,0x789abcde mov ax,0x1234 ; stuff in lower half push eax push dword fmt ; address of ctrl string call printf ; Call C function add esp,8 ; pop stack, 2 push times 4 bytes mov eax,0x789abcde mov ah,5 ; stuff byte push eax push dword fmt ; address of ctrl string call printf ; Call C function add esp,8 ; pop stack, 2 push times 4 bytes mov eax,0x789abcde mov al,6 ; stuff byte push eax push dword fmt ; address of ctrl string call printf ; Call C function add esp,8 ; pop stack, 2 push times 4 bytes pop ebx mov esp, ebp ; take down stack frame pop ebp ; same as "leave" op mov eax,0 ; normal, no error, return value ret ; return