|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么总是崩溃呢?哪位大神能帮忙找找原因呢?谢谢assume cs:code, ds:data;, ds:table, ss:stack
data segment
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
data ends
stack segment
db 16 dup (0)
stack ends
code segment
divdw:
;push bx
;mov cx, 10
push ax
mov ax, dx ;为什么第二次执行到这一步就崩溃呢?
mov dx, 0
div cx
mov bx, ax
pop ax
div cx
mov cx, dx
mov dx, bx
;pop bx
ret
year_str:
mov ax, word ptr ds:[si]
add si, 2
mov dx, word ptr ds:[si]
add si, 2
mov bx, 0
push cx
year_one:
mov cx, 10
push bx
call divdw
pop bx
push cx
inc bx
mov cx, ax
jcxz year_three
jmp short year_one
year_three:
mov cx, bx
year_four:
pop ax
mov ah, 2
mov byte ptr es:[bp + di], al
mov byte ptr es:[bp + di], ah
add di, 2
loop year_four
mov di, 0
add bp, 160
pop cx
loop year_str
start:
mov ax, data
mov ds, ax
mov ax, 0b800h
mov es, ax
mov ax, stack
mov ss, ax
mov sp, 16
mov cx, 3
mov di, 0
mov si, 0
call year_str
mov ax, 4c00h
int 21h
code ends
end start
assume cs:code, ds:data
data segment
dd 16, 22, 382, 1356, 2390, 8000, 16000, 24486, 50065, 97479, 140417, 197514
dd 345980, 590827, 803530, 1183000, 1843000, 2759000, 3753000, 4649000, 5937000
data ends
stack segment
db 16 dup (0)
stack ends
code segment
; 参数:
; dx:ax -> 被除数
; cx -> 除数
; 返回值:
; dx:ax -> 商
; cx -> 余数
divdw:
push bx
push ax
mov ax, dx
xor dx, dx
div cx ; H/n
mov bx, ax
pop ax
div cx ; (rem(H/n)*65536+L)/n
mov cx, dx
mov dx, bx
pop bx
ret
year_str:
mov ax, word ptr ds:[si]
add si, 2
mov dx, word ptr ds:[si]
add si, 2
xor bx, bx
push cx
year_one:
mov cx, 10
call divdw
push cx
inc bx ; 余数计数器
cmp ax, 0
jne year_one
mov cx, bx
xor di, di
year_four:
pop ax
add al, '0'
mov ah, 2 ; 绿色字体
mov word ptr es:[bp + di], ax
add di, 2
loop year_four
add bp, 160
pop cx
loop year_str
ret
start:
mov ax, data
mov ds, ax
mov ax, 0b800h
mov es, ax
mov ax, stack
mov ss, ax
mov sp, 16
mov cx, 10
mov di, 0
mov si, 0
xor bp, bp
call year_str
mov ax, 4c00h
int 21h
code ends
end start
|
|