Reputation: 11
I am working in emu8086 version 4.08. I have to make a student database. So, if I want to store a list of names or ID in an array of strings how can I do it? or is there any other way? Thanks in advance.
Here is the code I am trying:
include 'emu8086.inc'
.model small
.stack 100h
.data
str2 dw 20 dup('$')
.code
mov ax,@data
mov ds,ax
main proc
mov si,0
mov str2[si],"student1$"
add si,1
mov str2[si],"student2$"
add si,1
mov str2[si],"student3$"
add si,1
mov str2[si],"student4$"
mov ah,4ch
int 21h
endp main
DEFINE_SCAN_NUM
DEFINE_PRINT_STRING
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_PTHIS
Upvotes: 0
Views: 8504
Reputation: 39166
mov str2[si],"student1$"
You're wrong in what SI stands for. You think that it is an index in the array, but is is not. In assembly language it is an offset in memory (measured in bytes).
The string "student1$" has 9 characters and so you must provide room to store all of those characters, 1 byte per character. Furthermore you can't assign the complete string in one go. You'll have to use a loop for that.
First change the definition of the array and store the name in a tempory location:
str2 db 4*10 dup(0)
sname db "student1$"
This will give room for storing 4 student names of 9 characters plus an extra terminating character (if wanted).
Next use a loop to write a student name:
mov di, offset str2
mov si, offset sname
More:
mov al, [si]
mov [di], al
inc si
inc di
cmp al, "$"
jne More
For the next student the name will have to be written to str2 + 10
Upvotes: 3