« first day (2841 days earlier)      last day (12 days later) » 

9:52 AM
%include "../linux-ex/asm_io.inc"

extern printf

section .text

global main

main:
push ebp
mov ebp, esp

xor eax, eax

mov ax, [n1]
call print_int

leave
ret

section .data
n1 dw 01234h
n2 dw 02255h
n3 dw 04567h


(i am assuming the print_int I am using works and the problem is not there but in my understanding, since this was recommended by our professor)
this piece of NASM code on a 32bit architecture prints out 4660 as expected. If I change
mov ax, [n1]
to
movzx ax, [n1]
I get an output of 52. I know it doesnt make any sense to try to zero-extend 16 bits to 16 bits, since it is t
I don't understand why this happens though
I assume this channel has people familiar with assembly
 
 
6 hours later…
3:41 PM
@Silidrone read the manual, movzx with a 16bit operand size has a 8bit r/m source. It's only taking the 8bits at the memory address, and this being little endian... that's going to be 0x34
if you want a 16bit value you have to use the 32bit version with the encoding of 0x0F 0xB7 /r, if you use the 0x0F 0xB6 /r version you can only ever extend single byte. Strictly speaking the version you're using is "Move byte to word with zero-extension"
 
4:12 PM
thanks
 

« first day (2841 days earlier)      last day (12 days later) »