Read/Write Bytes From/To Registers

Programming, for all ages and all languages.
Post Reply
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Read/Write Bytes From/To Registers

Post by JoeTheProgrammer »

Can anyone explain to me how to do this in assembly?

Thanks,
Joseph
User avatar
Wave
Member
Member
Posts: 50
Joined: Sun Jan 20, 2008 5:51 am

Post 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
Conway's Law: If you have four groups working on a compiler, you'll get a 4-pass compiler.
Melvin Conway
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

How would you read then from the register?
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Re: Read/Write Bytes From/To Registers

Post 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
Post Reply