Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with puthex

Status
Not open for further replies.

humanic

Programmer
Oct 15, 2007
3
0
0
US
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
 
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top