NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: georgelappies on May 04, 2012, 08:09:31 PM

Title: How to split a 32 bit unsigned hex number into two 16 bit hex numbers?
Post by: georgelappies on May 04, 2012, 08:09:31 PM
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.
Title: Re: How to split a 32 bit unsigned hex number into two 16 bit hex numbers?
Post by: Bryant Keller on May 05, 2012, 12:10:43 AM
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
Title: Re: How to split a 32 bit unsigned hex number into two 16 bit hex numbers?
Post by: georgelappies on May 05, 2012, 08:13:03 AM
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.