The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: hywum on December 25, 2011, 10:16:35 PM

Title: Several variables in Data Segment
Post by: hywum on December 25, 2011, 10:16:35 PM
Hi,

I'm a beginner of 16-bit programming and have a problem that I'm not able to give account.
There are no errors, but there is alway printed "You pressed 'i'.".
This is my code:

DATA SEGMENT
Message db "You pressed 'i'.", "$"
Message2 db "You didn't press 'i'", "$"
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
start:

mov ah, 0
int 16h ; al = pressed key

cmp al, 'i'
jne ng

g:
mov dx, offset Message
mov ah, 9
int 21h
jmp _end
ng:
mov dx, offset Message2
mov ah, 9
int 21h
jmp start
_end:
mov ah, 0
int 16h

mov ah, 4Ch
int 21h
CODE ENDS
END start



Thx for your replies
Title: Re: Several variables in Data Segment
Post by: jj2007 on December 25, 2011, 10:38:55 PM
Assume is not sufficient - you need to load the register.

start:
  mov ax, @DATA ; set the DS register to DGROUP
  mov ds, ax ; for ds:si (lods)


Check also the macros included in DosBasic (http://www.masm32.com/board/index.php?topic=17991.msg151620#msg151620).
Title: Re: Several variables in Data Segment
Post by: hywum on December 25, 2011, 10:45:52 PM
Wow, this is great, it works fine. :)
Thank you very much!  :U