So, starting from an array of words, I have to create an array to include the digits of each given word, written in base 10.
So if I have
s DW 12345, 20778, 4596
the result should be this BYTE array
t DB 1, 2, 3, 4, 5, 2, 0, 7, 7, 8, 4, 5, 9, 6
I've been suggested how to do it, I've tried implementing it, but I get the following errors
Argument to operation or instruction has illegal size"
(regarding the "push al" and "pop al" lines)
Here's the code I've tried implementing:
ASSUME cs:text_,ds:data_
data_ SEGMENT
s dw 12345, 20778, 4596
l equ $-sir
d db (l/2)*5 dup (?)
data_ ENDS
text_ SEGMENT
start:
mov ax, data_
mov ds, ax
mov es, ax
mov si, offset s
mov di, offset d
mov cx, l ;storing the length of s
mov dl, 10
mov ax, [si] ;storing the data of si into ax so that the division can be made
cld ;setting the direction flag
jmp loop1
cloop1:
div dl ;divide by 10 so we can get the remainder
push al ;ERROR LINE ;my plan was to store the value of al into the stack, so I can store the remainder into al
mov al, ah
stosb ;we add the remainder to the final line
pop al ;ERROR LINE ;my plan was to get the value of al from the stack and do the instruction once againq
loop cloop1
loop1: ;the role of this loop is to repeat the instruction as long as there are words left (similar to while instruction in C++)
cmp ax, 0
jg cloop1 ;if there are words left, the code keeps on being executed
loop loop1
mov ax, 4c00h
int 21h
text_ ENDS
end start
And here's the idea it's based on (represented in C++):
nr=0;
while(x>0)
{c=x%10;
nr=nr+x*10;
x=x/10;
}
cout<<nr;
Thanks in advance and sorry for any mistakes. Any advice regarding my problem would be much appreciated