Reputation: 1
I am solving this question:
Push the first 10 even numbers onto a stack. Then, pop each number, check if it is divisible by 4, and if so, push it into a new stack. Finally, display the contents of the new stack.
I have correctly implemented the program logic but want to know how to effectively display the contents.
I am using emulator emu8086 to run the assembly code. I want to know which the best method is to display an array having numbers. Also can you tell what if we want to display specific number of elements of an array. In this code,
The code which I have written till now is below:
org 100h
mov di,0 ; to store no. of elements divisible by 4
mov al, 2h ;started even numbers from 2
mov cx,10
loop1: ;loop to push first ten even numbers to stack
push ax
add al,2h
loop loop1
mov bl, 4h
mov cx, 10
lea si,arr1
loop2: ; loop to pop elements and check divisibility by 4 and store themm in array
pop bp
mov ax,bp
div bx
cmp dx, 0h
je store
loop loop2
jmp break:
store: ;This portion will store the elements divisible by 4
add di, 1 ; Counting number of elements divisible by 4 to run loop to push them later
mov [SI], bp
inc SI
loop loop2
break:
mov cx,di ; di is no. of elements divisible by 4
lea si, arr1
loop3: ;loop to push the divisible elements { in array arr1} back to the stack
mov dl, [si]
push dx
inc si
loop loop3
display:
;logic to display array elements
ret
arr1 db 0 dup(5)
Upvotes: 0
Views: 24