The assembly code initializes arrays A
and B
, calculates the element-wise sum of these arrays, and stores the results in array C
. It also provides a procedure, printarray
, to print the entire contents of an array and uses this procedure to print the values of arrays A
, B
, and C
to the console. The code assumes a DOS-like environment and requires an x86-compatible system with appropriate assembly tools for execution.
yet it didnt give me any result and when i tried debugging it exited the program
.model small
.stack 100h
.data
A dw 12, 5, 8, -1, 4
B dw -2, 9, 0, 18, 3
C dw 5 dup (?)
N dw 5
.code
mov ax,@data
mov ds,ax
push offset A
push offset B
push offset C
push N
call arraysum
push offset A
push N
call printarray
mov ah, 2
mov dl, 10
int 21h
push offset B
push N
call printarray
mov ah, 2
mov dl, 10
int 21h
push offset C
push N
call printarray
mov ah, 2
mov dl, 10
int 21h
.exit
sum proc near
push bp
mov bp,sp
mov ax,[bp+4]
add ax,[bp+6]
pop bp
ret 4
sum endp
arraysum proc near
push bp
mov bp, sp
mov cx,[bp+4]
mov di, [bp + 10]
mov si, [bp + 8]
mov bx,[bp+6]
next:
push word ptr [di]
push word ptr [si]
call sum
pop word ptr [di]
pop word ptr [si]
mov [bx], ax
add si, 2
add di, 2
add bx, 2
dec cx
jnz next
pop bp
ret 8
arraysum endp
printnum proc near
push bp
mov bp, sp
mov ax, [bp + 4]
mov bx, 10
mov cx, 0
cmp ax, 0
jge next
neg ax
next1:
mov dx, 0
div bx
add dx, 30h
push dx
inc cx
cmp ax, 0
jne next1
mov ax,[bp+4]
cmp ax, 0
jge sof
push -
inc cx
sof:
cmp cx, 0
jz ext
pop dx
mov ah, 2
int 21h
dec cx
jmp sof
ext:
pop bp
ret 2
printnum endp
printarray proc near
push bp
mov bp, sp
mov cx, [bp + 4]
mov si, [bp + 6]
print_loop:
push word ptr [si]
call printnum
add sp, 2
inc si
dec cx
jnz print_loop
pop bp
ret 4
printarray endp
end