an assembly code to find max and find the max factorial

123 Views Asked by At

I've been working on this code it supposed to Find the maximum from num1 and then calculate its factorial. then it stores the factorial 'fact'

but it seems that it keeps looping and it doesn't reach the end of the program

if anyone can guide me to the problem I would appreciate it... Here's the code

[ORG 0x100]
         jmp start

num1:    dw 6, 3, 5, 2, 8, 1, 4, 7
max:     dw 0
fact:    dw 0

max1:    push ax
         push bx
         push cx

         mov ax, [bx]
         dec cx

again2:  add bx, 2
         cmp ax, [bx]
         jg next
         mov ax, [bx]

next:    loop again2
         mov [di], ax
         pop cx
         pop bx
         pop ax
         ret

f:       push bp
         mov bp,sp
         push ax
         push dx
         cmp word[bp+4],1
         je exit

         sub sp,2
         mov ax,[bp+4]

         dec ax
         push ax
         call f

         pop ax
         mov dx,0
         mul word[bp+4]
         mov [bp+6],ax
         jmp exit2

exit:    mov word[bp+6],1

exit2:   pop dx
         pop ax
         pop bp
         ret 2

start:   mov bx, num1
         mov cx, 8
         mov di, max
         call max1
         sub sp,2
         push max
         call f
         pop ax

end:     mov ax, 0x4c00 ;terminate program
         int 0x21
0

There are 0 best solutions below