目录
写在前面
编译器为 MASM-v6.11
写的一坨屎。
计算斐波那契数列第 \(i\) 项
最多支持输出 30 位十进制数。
为第 22 行的 cx 寄存器赋值即为所求的项。
.model large
assume cs:code, ss:stack
string segment
db 30 dup (0), 0
string ends
data segment
a1 db 1, 29 dup (0)
a2 db 1, 29 dup (0)
a3 db 30 dup (0)
data ends
stack segment
dw 20H dup(0)
stack ends
code segment
main:
call init
mov cx, 120 ;number of fib
sub cx, 2
main_s1:
call get_fib
call move_fib
loop main_s1
call transforming
call show_string
mov ax, 4c00h
int 21h
init:
mov ax, stack
mov ss, ax
mov sp, 20H
ret
get_fib:
push dx
push si
push ax
push bx
push cx
push ds
mov ax, data
mov ds, ax
mov cx, 30
mov si, 0
mov ax, 0
get_fib_s:
add al, ds:[si]
mov bl, ds:[si + 30]
add al, bl
mov bl, 10
div bl
mov ds:[si + 60], ah
mov ah, 0
inc si
loop get_fib_s
pop ds
pop cx
pop bx
pop ax
pop si
pop dx
ret
move_fib:
push dx
push si
push ax
push bx
push cx
push ds
mov ax, data
mov ds, ax
mov cx, 30
mov si, 0
move_fib_s1:
mov al, ds:[si + 30]
mov ds:[si], al
inc si
loop move_fib_s1
mov cx, 30
mov si, 0
move_fib_s2:
mov al, ds:[si + 60]
mov ds:[si + 30], al
inc si
loop move_fib_s2
pop ds
pop cx
pop bx
pop ax
pop si
pop dx
ret
transforming:
push dx
push si
push ax
push bx
push cx
push ds
push es
mov ax, data
mov ds, ax
mov ax, string
mov es, ax
mov cx, 30
mov si, 0
transforming_s1:
mov al, ds:[si + 30]
add al, '0'
mov es:[si], al
inc si
loop transforming_s1
mov cx, 15
mov si, 0
mov bx, 29
transforming_s2:
mov al, es:[si]
mov dl, es:[bx]
mov es:[bx], al
mov es:[si], dl
inc si
sub bx, 1
loop transforming_s2
pop es
pop ds
pop cx
pop bx
pop ax
pop si
pop dx
ret
show_string:
push dx
push si
push ax
push bx
push cx
push ds
push es
mov dh, 24 ;line
mov dl, 0 ;column
mov cl, 000fh ;color
mov ax, string
mov ds, ax
mov si, 0
mov ax, 0b800h
mov es, ax
mov ax, 00a0h
mul dh
mov dh, 0
add ax, dx
add ax, dx
mov bx, ax
mov al, cl
mov ch, 0
mov si, 0
show_string_s:
mov cl, ds:[si]
jcxz show_string_ok
mov es:[bx], cl
inc bx
mov es:[bx], al
inc bx
inc si
jmp short show_string_s
show_string_ok:
pop es
pop ds
pop cx
pop bx
pop ax
pop si
pop dx
ret
code ends
end
写在最后
写的一坨屎。
标签:汇编语言,周速通,OIer,pop,mov,si,push,ax,ds From: https://www.cnblogs.com/luckyblock/p/17778317.html