I'm writing a function to print each register in my 16-bit real mode assembly operating system. I've come across a few problems:
1 Moving a 16-bit register into an 8-bit one
mov al, bx
This gives me error: invalid combinations of opcodes and operands
. Is there anyway that I could do this?
2 Does moving a value into ax
affect ah
and/or al
?
mov ah, 0x5
mov al, 0x10
mov ax, 0x20
Will ah
still hold 0x5 and al
hold 0x10?
3 Printing the hexadecimal value of a register and not the ascii code?
mov ah, 0x0e
mov al, 0x4d
int 0x10
This outputs the character 'm' and not 0x4d nor 77 nor 1001101 etc. Is the only option to convert 4d to 0x34 and 0x64 and then print?
mov al, bl
. Going the other way, you can use movzx
or movsx
to zero- or sign-extend.AL
and AH
are the two halves of AX
(similarly for other registers, and further extended to 32 and 64 bit registers).