I have a trouble with simple assembler program.I don’t know what i why happens but there is problem.
Task is : Compute scalar product of two arrays in assembler (emu 8086)
Here is my code
; multi-segment executable file template.
data segment
; add your data here!
n1 db 1,2,3
n2 db 4,5,6
i db ?
j db ?
k dw ?
pkey db "press any key...$"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
mov al,00h
mov ah,02h
mov ch,00h
mov cl,03h
mov bx,offset n1
ciklus:
mov dl,[bx]
;add dl,30h
mov j,0d
add j,dl
int 21h
mov al,j
mov ah,0h
inc bx
inc bx
inc bx
mov dl,[bx]
;add dl,30h
mov i,0d
add i,dl
mul i
mov k,ax
mov al,00h
mov ah,02h
int 21h
dec bx
dec bx
dec bx
inc bx
loop ciklus
lea dx, pkey
mov ah, 9
int 21h ; output string at ds:dx
; wait for any key....
mov ah, 1
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
ends
end start ; set entry point and stop the assembler.
So when i run program step by step i see strange values in ax. I want
1×4 2×5 3×6 = > 4 10 18 to save in some variable and print to screen .
If someone can help me i will be grateful.
P.S this i’m noob in assembler programming so don’t be angry of my stupid question.
After the
ciklus:label, you are adding 0x30 todl, then addingdltoj, soj >= 0x30at this point. After the interrupt you setaltoj, andahto0x0, soax >= 0x30. Later you add0x30todl, then adddltoi.So
mul iis effectively: [dx:ax] = i * ax, which is going to be at least (0x30 * 0x30), i.e.,ax >= 2304, dx = 0. Larger, depending on the contents of [bx], i, j.After the
mulyou overwrite theaxregister with the value:0x200(512), anyway, so the results are lost. In short, you need to look at saving your runningax [ah:al]register before clobbering it for use as the interrupt service code.P.S. You might consider using the
sianddiregisters to save working values.