3

I am new in assembly , I am using emu8086

I was trying to print two elements of an array , but I could not print the second element

Here is my code:

.MODEL SMALL

.STACK 100H  

.DATA 
MSG DB 'HI','GOOD$'

.CODE 

MAIN PROC

MOV AX,@DATA
MOV DS,AX
 
MOV AH,2
MOV DL,MSG
INT 21H  

MOV AH,2
MOV DL,MSG+1
INT 21H 

MOV AH,4CH
INT 21H

MAIN ENDP

END MAIN

at output hi is printed , good is not printed . please correct me how can print the second element.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
000
  • 405
  • 5
  • 20
  • 1
    You can loop through the whole array and print the value of offset. Check this link: [link](http://stackoverflow.com/questions/35709437/printing-array-getting-strange-output-emu8086) – nim_10 May 23 '16 at 07:16
  • 6
    1) `int 21h / ah=02h` prints individual characters, to print a string you would use `int 21h / ah=09h`. 2) All strings that you print with `int 21h / ah = 09h` need to be `'$'`-terminated; currently only `'GOOD'` is `'$`-terminated. 3) `'GOOD'` starts at `MSG+2`, not `MSG+1` (and if you add a `'$'`-terminator to `'HI'`, `'GOOD'` would start at `MSG+3`). It would simplify things if you created another array containing the address of each string, which you then could process in a loop. – Michael May 23 '16 at 07:31

1 Answers1

2

If all you want to do is print "HIGOOD" then write:

MOV AH,2
MOV DL,MSG
INT 21H  
MOV DL,MSG+1
INT 21H
MOV DL,MSG+2
INT 21H  
MOV DL,MSG+3
INT 21H
MOV DL,MSG+4
INT 21H  
MOV DL,MSG+5
INT 21H

A far better approach is to "$"-terminate both strings like MSG DB 'HI$','GOOD$' and then use the string output function 09h:

MSG DB 'HI$','GOOD$'
...
mov ah, 09h
mov dx, offset MSG
int 21h
mov dx, offset MSG+3
int 21h

Even better is to assign separate labels to your strings:

MSG1 DB 'HI$'
MSG2 DB 'GOOD$'
...
mov ah, 09h
mov dx, offset MSG1
int 21h
mov dx, offset MSG2
int 21h
Fifoernik
  • 9,779
  • 1
  • 21
  • 27