Author Topic: How to split a 32 bit unsigned hex number into two 16 bit hex numbers?  (Read 7557 times)

Offline georgelappies

  • Jr. Member
  • *
  • Posts: 12
Hi all

I have the following problem. I have a number like this:

FA34ED67

Now this is a 32 bit hex number right, I now need to split this number into 16 high bits and 16 low bits so that for instance this number can be loaded into AX:BX. The problem is I cannot use EAX or any 32 bit registers, I can only use DOS 16 bit mode.

Basically the intro portion of the code will be something like this:

Code: [Select]
bits 16
org 0x100

hexNum: dq FA34ED67h

Now for the life of me I cannot figure out how to get this 32 bit hex number into 16 bit registers so I can properly work with it.

Any suggestions will be most appreciated.

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Well, one problem is 'DQ' defines a quadword, not a dword, so that needs to be fixed. Basically, you can do something like this.

Code: [Select]
BITS 16
ORG 0x100

mov ax, [hexNum]
mov bx, [hexNum + 2]

; do whatever with the code.

mov ah, 0x4C
int 0x21

hexNum: DD 0xFA34ED67

About Bryant Keller
bkeller@about.me

Offline georgelappies

  • Jr. Member
  • *
  • Posts: 12
Well, one problem is 'DQ' defines a quadword, not a dword, so that needs to be fixed. Basically, you can do something like this.

Code: [Select]
BITS 16
ORG 0x100

mov ax, [hexNum]
mov bx, [hexNum + 2]

; do whatever with the code.

mov ah, 0x4C
int 0x21

hexNum: DD 0xFA34ED67

Thanks a lot Bryant, much appreciated.