PDA

View Full Version : moving byte pointed to by contents of a register into another register. dos debug.



Brian
04-18-2003, 01:23 PM
I'm using MS DOS debug (weird, i know, but I'm going for REALLY small) to write a little XOR encryption program, but I'm confused about one thing.

I have moved an address into AX and I am trying to load the first byte from that address into BH, but with no success.


mov bh, [ax]

doesnt work, although



mov bh, [150]

does, but I need the first one to work.

how can i resolve this? Thanks in advance.
Brian, of cprogramming.com

Perspective
04-18-2003, 02:26 PM
im only familiar with MIPS assembly but the ideas should be the same.

you could 'and' the contents of AX with 0x000f, then copy that into BH, this would give you the first byte of AX.

if this has nothing to do with your problem ignore me.

Brian
04-18-2003, 02:46 PM
Originally posted by Perspective
im only familiar with MIPS assembly but the ideas should be the same.

you could 'and' the contents of AX with 0x000f, then copy that into BH, this would give you the first byte of AX.

if this has nothing to do with your problem ignore me.

thanks for the reply, but i dont think thats what it is. what i mean is the contents of AX are an address in memory and I want to move a byte of data from that address into BH (AX is a pointer, technically.)

Perspective
04-18-2003, 03:44 PM
yeah, oops i had the hex number wrong above. if AX holds a 4 byte address then...

AX & 0x0000 00FF = the low order byte from AX with the other bytes masked to 0's

ex.

AX = 0x0FD8 74AE

BH = AX & 0x0000 00FF = 0x0000 00AE

this will give you one byte from AX which can then be stored in BH. i am assuming these are 32 bit registers that need the 0 padding.

if this still has nothing to do with your problem, ignore me again..

ygfperson
04-18-2003, 04:05 PM
You're wrong... AX,Bx,CX, and DX are all 16 bit registers. EAX, EBX, etc.. are 32 bit, but unavailiable under DOS's debug.

Opcodes are very picky things. You can't combine things like you can in C or for that matter any modern programming language out there. Often, if it doesn't work, you have to expand it into two or more commands.

ie:

mov bh, [ax]

should be
push ep
mov ep, ax
mov bh, [ep]
pop ep


(i haven't tested it... try it out and tell me if it works.)

Perspective
04-18-2003, 04:14 PM
Originally posted by ygfperson
You're wrong... AX,Bx,CX, and DX are all 16 bit registers. EAX, EBX, etc.. are 32 bit, but unavailiable under DOS's debug.


oh, i had no idea. srry for the confusion

Brian
04-18-2003, 05:48 PM
Originally posted by ygfperson
You're wrong... AX,Bx,CX, and DX are all 16 bit registers. EAX, EBX, etc.. are 32 bit, but unavailiable under DOS's debug.

Opcodes are very picky things. You can't combine things like you can in C or for that matter any modern programming language out there. Often, if it doesn't work, you have to expand it into two or more commands.

ie:

mov bh, [ax]

should be
push ep
mov ep, ax
mov bh, [ep]
pop ep


(i haven't tested it... try it out and tell me if it works.)
i get the idea, but debug doesnt seem to recognise ep. argh

wait, i got it! i guess you meant bp. woo. it works. thanks.