8086汇编显示整形数组,输入并显示整形数组(函数实现,输入范围:-32768~32767)
Posted u25th_engineer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8086汇编显示整形数组,输入并显示整形数组(函数实现,输入范围:-32768~32767)相关的知识,希望对你有一定的参考价值。
图 1 程序运行示意
图 2 程序运行示意
图 3 程序运行示意
stack segment stack
db 512 dup(?)
stack ends
data segment
;arr dw 25, 30, 36, 100, 23, 24, 9999
arr dw 10085, 32061, 14723, 19165, 4242, 11128, 12435
;arr dw -30, 338, 8, -32768, 6, 32767, 23
arr2 dw 5 dup(?)
msg1 db "The first integer arr is as follows:", 0ah, 0dh, '$'
msg2 db "Enter the second integer array:", 0ah, 0dh, '$'
msg3 db "The second integer arr is as follows:", 0ah, 0dh, '$'
string1 db "Press any key to continue!", 0ah, 0dh, '$'
data ends
code segment
assume ds: data, cs: code, ss: stack
main:
mov ax, stack
mov ss, ax
mov ax, data
mov ds, ax
lea dx, msg1
mov ah, 09h
int 21h
lea ax, arr
push ax
mov ax, 7
push ax
call far ptr print_arr
call far ptr lineFeed
;pop ax
;pop ax
;lea si, arr
;xor di, di
;push [di + 2]
;push [di]
;call far ptr swap_num
;lea ax, arr
;push ax
;mov ax, 7
;push ax
;call far ptr print_arr
;call far ptr lineFeed
;pop ax
;pop ax
lea dx, msg2
mov ah, 09h
int 21h
lea ax, arr2
push ax
mov ax, 5
push ax
call far ptr read_arr
;pop ax
;pop ax
lea dx, msg3
mov ah, 09h
int 21h
lea ax, arr2
push ax
mov ax, 5
push ax
call far ptr print_arr
call far ptr lineFeed
;pop ax
;pop ax
jmp done
swap_num proc far
push bp
mov bp, sp
push ax
push bx
mov ax, [bp+10]
mov bx, [bp+12]
mov [bp+10], bx
mov [bp+12], ax
pop bx
pop ax
pop bp
ret
swap_num endp
read_arr proc far
push bp
push si
push di
mov bp, sp
mov si, [bp]
xor di, di
mov cx, [bp+10]
readArr:
call far ptr readsiw
mov [di], ax
add di, 2
loop readArr
pop di
pop si
pop bp
ret
read_arr endp
print_arr proc far
push bp
push si
push di
mov bp,sp
mov si, [bp]
xor di, di
mov cx, [bp+10] ; why must to be [bp+10] here?
printArr:
mov ax, [di]
call far ptr dispsiw
;call far ptr lineFeed
call far ptr space
add di, 2
loop printArr
pop di
pop si
pop bp
ret
print_arr endp
readsiw proc far
push bx
push cx
push dx
xor bx, bx
xor cx, cx
mov ah, 1
int 21h
cmp al, '+'
jz rsiw1
cmp al, '-'
jnz rsiw2
mov cx, -1
rsiw1:
mov ah, 1
int 21h
rsiw2:
cmp al, '0'
jb rsiw3
cmp al, '9'
ja rsiw3
sub al, 30h
xor ah, ah
shl bx, 1
mov dx, bx
shl bx, 1
shl bx, 1
add bx, dx
add bx, ax
jmp rsiw1
rsiw3:
cmp cx, 0
jz rsiw4
neg bx
rsiw4:
mov ax, bx
pop dx
pop cx
pop bx
ret
readsiw endp
dispsiw proc far
push ax
push bx
push dx
test ax, ax
jnz dsiw1
mov dl, '0'
mov ah, 2
int 21h
jmp dsiw5
dsiw1:
jns dsiw2
mov bx, ax
mov dl, '-'
mov ah, 2
int 21h
mov ax, bx
neg ax
dsiw2:
mov bx, 10
push bx
dsiw3:
cmp ax, 0
jz dsiw4
xor dx, dx
div bx
add dl, 30h
push dx
jmp dsiw3
dsiw4:
pop dx
cmp dl, 10
je dsiw5
mov ah, 2
int 21h
jmp dsiw4
dsiw5:
pop dx
pop bx
pop ax
ret
dispsiw endp
lineFeed proc far
push ax
push dx
mov dl, 0dh
mov ah, 2
int 21h
mov dl, 0ah
mov ah, 2
int 21h
pop dx
pop ax
ret
lineFeed endp
space proc far
pushf
push ax
push dx
mov ah,02h
mov dl,' '
int 21h
pop dx
pop ax
popf
ret
space endp
done:
lea dx, string1
mov ah, 09h
int 21h
mov ah, 07h
int 21h
mov ah, 4ch
int 21h
code ends
end main
以上是关于8086汇编显示整形数组,输入并显示整形数组(函数实现,输入范围:-32768~32767)的主要内容,如果未能解决你的问题,请参考以下文章
8086汇编显示整形数组,输入并显示整形数组(函数实现,输入范围:-32768~32767)
8086汇编显示整形数组,输入并显示整形数组(函数实现,输入范围:-32768~32767)
8086汇编显示整形数组,输入并显示整形数组(函数实现,输入范围:-32768~32767)
8086汇编求整形数组的最大值与最小值(函数实现,输入范围:-32768~32767)