Created
December 1, 2019 14:08
-
-
Save candh/b89919bd3478dff4df7a3328fd5b43de to your computer and use it in GitHub Desktop.
find largest number in assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.stack 100h | |
.model small | |
.data | |
arr dw 12, 25, 7, 44 | |
N dw 4 | |
MAXN dw 0 | |
msg1 db "Max = $" | |
.code | |
main proc | |
mov ax, @data | |
mov ds, ax | |
push N | |
call max | |
mov ah, 9 | |
lea dx, msg1 | |
int 21h | |
mov cx, 0 | |
mov ax, MAXN | |
pstack: | |
inc cx | |
mov dl, 10 | |
div dl | |
mov dl, al ; store quotient | |
and ax, 0FF00h ; clear quotient | |
xchg al, ah ; remainder in al | |
push ax | |
mov al, dl ; restore quotient | |
cmp al, 0 | |
jne pstack ; repeat while quotient is non - zero | |
print: | |
pop ax | |
mov dl, al | |
add dl, 30h | |
mov ah, 2 | |
int 21h | |
loop print | |
mov ax, 4Ch | |
int 21h | |
main endp | |
max proc | |
push bp | |
mov bp, sp | |
mov ax, bp[4] | |
mov N, ax | |
;if | |
cmp N, 1 | |
jne endif | |
;else | |
mov cx, arr[0] | |
mov MAXN, cx ; maxn = firstel | |
jmp return | |
endif: | |
dec N | |
push N | |
call max | |
; get N | |
mov bx, bp[4] | |
; N = (N - 1) * 2 | |
dec bx | |
shl bx, 1 | |
mov cx, arr[bx] | |
;if | |
cmp cx, MAXN | |
jl return | |
;else | |
mov MAXN, cx | |
return: | |
pop bp | |
ret 2 | |
max endp | |
end main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment