Thread: moving byte pointed to by contents of a register into another register. dos debug.

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

    moving byte pointed to by contents of a register into another register. dos debug.

    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.
    Code:
    mov bh, [ax]
    doesnt work, although

    Code:
    mov bh, [150]
    does, but I need the first one to work.

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

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    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.)

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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..

  5. #5
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    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.)

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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

  7. #7
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    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.
    Last edited by Brian; 04-18-2003 at 05:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 05:19 AM
  4. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM