Page 1 of 1

Read/Write Bytes From/To Registers

Posted: Mon Jan 21, 2008 11:56 am
by JoeTheProgrammer
Can anyone explain to me how to do this in assembly?

Thanks,
Joseph

Posted: Mon Jan 21, 2008 1:00 pm
by Wave
Shouldn't that be in general programming?

Code: Select all

; The intel syntax is:
mov register, value
; Example:
mov eax, 6298503
mov bh, 34

Posted: Mon Jan 21, 2008 1:08 pm
by JoeTheProgrammer
How would you read then from the register?

Re: Read/Write Bytes From/To Registers

Posted: Mon Jan 21, 2008 1:15 pm
by mathematician
JoeTheProgrammer wrote:Can anyone explain to me how to do this in assembly?

Thanks,
Joseph
If you are talking about peripheral chips like the IDE controller (for instance), you usually use in/out instructions. For example:

Code: Select all

mov dx, 1f0h
in ax,dx                (read primary IDE controller's data register)

in al, 21h              (read the master PIC's mask register)

mov dx, 3d4h
out dx,al              (write to the CRT controller's address register)
For port numbers > 255 you have to load the address into dx first. Which port numbers attach to which devices is obviously information which has to be retrieved from relevant documentation.


POST SCRIPT:
You read from a processor's register by using the same MOV instruction you use to write it:

Code: Select all

mov  some_data,  ax      (store the contents of ax in the variable some_data

mov [ebx], cl       (store the value of cl in the memory location pointed to by ebx