Friday, August 24, 2018

assembly - Addressing issue with mov instruction in x86



I am trying to write a code which prints a character on the VGA display (seen on QEmu window). Here is my code:
(This file is putInMemory.asm)




;Put the charcter in cx at the beginning of line number given by dx
printInMemory:
pusha
mov es, 0xb000
mov ax, 0x8000
mult:
cmp dx, 0x1
je done
add ax, 160
jmp mult

done:
mov [es:ax], cx
add ax, 1
mov [es:ax], 0x7
popa
ret


I want to copy the ascii code contained in register cx to memory location 0xb80a0, which is the address of beginning of the 2nd line in the display. Here is the code:




[org 0x7c00]
mov cx, 'e'
mov dx, 0x2
call putInMemory
jmp $

%include "putInMemory.asm"

times 510-($-$$) db 0
dw 0xaa55



When I assemble the above code using nasm, I get the following error in the first code:
putInMemory.asm:12: error: invalid effective address
How can I use segmented addressing in mov instruction?


Answer



You can't use ax when specifying an effective address in 16-bit code (see the table named "16-Bit Addressing Forms with the ModR/M Byte" in Intel's Software Developer's Manual). Use bx, bp, si or di instead.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...