×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help with puthex

Help with puthex

Help with puthex

(OP)
I am trying to write a simple assembly program that allows me to assign values and display them at certain points. I am only at "checkpoint A", which means I have yet to do any swapping, and already I am not showing what I expected. Why do I not see the output being alpha, beta, ... that is, why not 23, AB01, EF45, 89, CD67?

;===========================================================
           DOSSEG
.MODEL  SMALL,BASIC
;===========================================================

     EXTRN   PUTHEX:FAR
     EXTRN   PUTSTRNG:FAR       
     EXTRN   NEWLINE:FAR         

;
; S T A C K   S E G M E N T   D E F I N I T I O N
;
           .STACK  256
;===========================================================
;
; D A T A   S E G M E N T   D E F I N I T I O N
;
.DATA
ALPHA      DB      35
BETA       DW      01ABH
GAMMA      DW      45EFH
LAMDA      DB      CONSTANT
OMEGA      DW      67CDH
CONSTANT   EQU     10001001B

;===========================================================
; C O D E   S E G M E N T   D E F I N I T I O N
                      .CODE
              ASSUME  DS:NOTHING,ES:DGROUP

PR_2_2:       
;*** CHECKPOINT A ***
       MOV     AL,ALPHA
        MOV     BL,0                ;   DISPLAY 8 BITS
           CALL    PUTHEX              ;   OF NUMBER IN HEX
           CALL    NEWLINE             ;   DISPLAY NEWLINE

       MOV     AX,BETA
        MOV     BL,1                ;   DISPLAY 16 BITS
           CALL    PUTHEX             
           CALL    NEWLINE            

       MOV     AX,GAMMA
        MOV     BL,1                ;   DISPLAY 16 BITS
           CALL    PUTHEX             
           CALL    NEWLINE             

       MOV     AL,LAMDA
        MOV     BL,0                ;   DISPLAY 8 BITS
           CALL    PUTHEX             
           CALL    NEWLINE           

       MOV     AX,OMEGA
        MOV     BL,1                ;   DISPLAY 16 BITS
           CALL    PUTHEX              
           CALL    NEWLINE          



           MOV     AH,CONSTANT
           MOV     AL,ALPHA
           MOV     BX,GAMMA
           XCHG    AH,BH
           XCHG    AX,BETA
           MOV     ALPHA,AH
           MOV     LAMDA,AL
;*** CHECKPOINT B ***

           MOV     CX,OMEGA
           XCHG    BL,CH
           MOV     GAMMA,BX
           MOV     OMEGA,CX
;*** CHECKPOINT C ***
           .EXIT                      ;RETURN TO DOS

           END     PR_2_2
 

RE: Help with puthex

     Even though you have a segment assume (DS:Nothing, ES:DGROUP) you should still explicitly set the segment registers (with the exception of SS and CS) to the appropiate segment; i.e. DS to DATA, and ES to DGROUP. Always consider the value of your registers to be undetermined at the start of program execution.  DS is probally not pointing to DATA thereby causing you to access the incorrect data. When you assemble the following code:

  MOV AH, ALPHA
what the computer actually sees is:

  "Take the byte at offset 0 (which is labeled ALPHA) in the Segment pointed to by DS and load it into AH."

Try using the following code to set your DS register to your DATA Seg:

  MOV AX, SEGMENT DATA  ;  Get Segment for Data Segment
  MOV DS, AH            ;  Load it into DS

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close