Hi guys! im having a problem with an exercise and i can't find the solution. the program have to sub the contents of the second array from the first and mov the result to the third. This is what i did so far.

TITLE ARITHMETIC2
    DOSSEG
    .MODEL SMALL

    .STACK 100h

    .DATA
arrayE DB 112, 112, -32, -32, -128
arrayF DB 80, 120, 112, -80, 128
arrayX DB 2 DUP (10)

    .CODE
start:    MOV AX,@DATA
           MOV DS,AX
    
    MOV SI, OFFSET arrayE
    MOV DI, OFFSET arrayF
    MOV SP, OFFSET arrayX
    MOV CX, 5    
    
loopi:     
    MOV AX, [SI]
    MOV BX, [DI]
    MOV DX, [SP]
    SUB AX , BX
    
    MOV DX, AX
    INC SI
    INC DI
    INC SP ;this is wrong, what should i write here?
    LOOP loopi
terminate:    MOV AX, 4C00H
    INT 21H
    END start

You simply forgot to store the result to the final array.

loopi:
MOV AX, [SI]
MOV BX, [DI]
MOV DX, [SP]
SUB AX , BX

MOV DX, AX
MOV [SP], DX   <<<  add this line
INC SI
INC DI
INC SP ;this is wrong, what should i write here?
LOOP loopi

Nathan.

SP is a special purpose register and it should never be used for anything other than what it was intended and you realize that anyway by your comment this is wrong. You've got the right idea using index registgers, but you're failing to use instructions that give these registers thier potential, like LODS & STOS.

loopi:
        lodsb
        sub      al, [di]
        stosb
        loop     loopi

In the first part of you app move the contents of arrayE to arrayX and then setup

mov     si, arrayE
        mov     di, arrayX
        mov     cx, 5
        rep     movsb

Then you can execute the snippet before this one. Realize my example is over simplistic and I use NASM, but I sure you'll get the idea.

In assembly programming try to avoid moving data from memory to register, doing a calculation and then moving back again. There is unecessary overhead in both code and time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.