My problem is not too big but I don't understand something and I wanted to ask for some help.
We are learning about Assembly .x86 language and I got stuck at SUB arithmetic Instruction.
This is the code:
INCLUDE Irvine32.inc
.data
val_A DWORD 1234h
val_B DWORD 144h
.code
main proc
MOV EAX, val_B ;This works
SUB EAX, val_A
CALL WriteInt
CALL Crlf
INVOKE ExitProcess, 0
main endp
.stack
dw 100 dup(? )
end main
When I try to put like this:
MOV EAX, val_A
MOV EBX, val_B
SUB EBX, EAX
It doesnt work. We learned that [SUB] arithmetical intstruction works just as [MOV] and [ADD] but when I try to use it as [SUB reg/reg] absolutely gives nothing only shows what is in the EAX register. I use Visual Studio I am not sure if that's the issue.
WriteInt
is hard-coded to display value ofeax
, it can't read your mind to switch toebx
instead. Overall almost no asm instruction does care about what was executed before, all the "state" of CPU is basically in the content of registers, and the current content of memory, it has little idea how it got into particular state (for example the CPU does not know it is "inside" subroutine, and how deep). You can use built-in debugger in Visual Studio to check content of registers and memory after each instruction execution (single stepping the code), which I strongly recommend. – Ped7g