Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print elements of array in assembly

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.

like image 454
000 Avatar asked Dec 19 '25 05:12

000


1 Answers

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
like image 168
Fifoernik Avatar answered Dec 20 '25 22:12

Fifoernik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!