I am reading a book by Paul Carter pcasm . It uses NASM, the C driver application that calls my build code, and a companion library that simplifies basic I / O operations in the assembly.
This is what my function that will be called from C looks like this:
segment .text global _asm_main _asm_main: enter 0,0 ; setup routine pusha mov bx, 0034h ; bx = 52 (stored in 16 bits) mov cl, bl ; cl = lower 8-bits of bx mov eax, ecx call print_int popa mov eax, 0 ; return back to C leave ret
The print_int function prints the value store in eax as an integer. But this outputs garbage to stdout:
4200244
If I initialize the ecx register to 0 with mov ecx, 0000h before using it, I get the expected result:
52
Initialization is always required, and if so, is there a quick way to initialize all registers to 0 (or a user-defined initializer) from C or NASM?
I am using XP32, MinGW 4.4.0 and NASM 2.09.04.
source share