Printing the hexadecimal value of assembly registers, moving 16 bit registers into 8 bit ones and other assembly questions

StackOverflow https://stackoverflow.com//questions/23017777

Question

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?

Was it helpful?

Solution

  1. Since 16 bits don't fit into 8 bits, you can't do that. Use the appropriate 8 bit register, such as mov al, bl. Going the other way, you can use movzx or movsx to zero- or sign-extend.
  2. Yes, AL and AH are the two halves of AX (similarly for other registers, and further extended to 32 and 64 bit registers).
  3. You need to convert, yes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top