本文介绍了Assembly(TASM)程序在运行时崩溃,但在调试器(涡轮调试器)中工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序(assembly tasm 16bit)应该打印一个数组的条形图表示.现在它仅支持specificarray,但将来我会增加对一般情况的支持.该代码在调试器中运行良好,并将条形打印为但是在运行时,代码被卡住了,并且可以打印任何内容.除PrintArr以外的所有功能均按预期单独工作.我无法在调试中发现问题,因为问题似乎在调试器中存在.

My program(assembly tasm 16bit) supposed to print a bar graph represtion for an array.Right now its only supports specificarray but I will add support for general cases in the future.The code works fine in debugger and prints the bars as expcted.But in run the code gets stuck and dosent print anything. All the functions apart from PrintArr were working separately as expcted. I cant find my problam in debugging beacouse the problame dosent seem to exist in the debugger.

;
IDEAL
MODEL small
STACK 100h
DATASEG
; --------------------------
; Your variables here
; --------------------------
arr db 3,1,2
screen_width dw 300
screen_height dw 190
plo dw 0
var db ?
CODESEG
;works on tasm syntex 16 bit
proc FindWidthForColAndSpace
;finds the width for each col and space
;input:
;1.number of cols
;2.screen width
;ouput:
;1.space
;2.width
push bp
mov bp,sp
push ax
push bx
push cx
push dx
mov ax,[bp+4];sceen width
mov bx,[bp+6];number of cols
div bx
xor dx,dx
mov bx,ax
mov cx,5
mul cx
xor dx,dx
mov cx,100
div cx
xor dx,dx
sub bx,ax
mov [bp+4],ax
mov [bp+6],bx
pop dx
pop cx
pop bx
pop ax
pop bp
ret
endp FindWidthForColAndSpace
proc FindHeight
;finds the pixel repsention for
;input:
;1.screen height
;2.highest value
;3.lowest value
;ouput:
;1.height
push bp
mov bp,sp
push ax
push bx
push cx
push dx
xor dx,dx
mov cx,[bp+4];lowest value
mov bx,[bp+6];highest value
mov ax,[bp+8];screen height
div bx
mov [bp+8],ax
pop dx
pop cx
pop bx
pop ax
pop bp
ret 4
endp FindHeight
proc PrintLine
;prints a line
;1.length
;2.colour
;3.x
;4.y
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push si
mov cx,[bp+10];leangth
mov dx,[bp+4];y
mov al,[bp+8];colour
mov si,[bp+6];x
mov ah,0ch
xor bx,bx
pl:
    push cx
    mov cx,si
    int 10h
    inc si
    pop cx
loop pl
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 8
endp PrintLine
;clean screen
proc Cls
push ax
push cx
mov cx,200
xor ax,ax
Clean:
    push 320
    push 0
    push 0
    push ax
    call PrintLine
    inc ax
loop Clean
pop cx
pop ax
ret
endp cls
proc PrintSquare
;print a square
;input:
;1.height
;2.leangth
;3.colour
;4.x
;5.y
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push di
push si
mov cx,[bp+12]
mov ax,[bp+10]
mov bx,[bp+8]
mov dx,[bp+6]
mov di,[bp+4]
xor si,si
print:
mov di,[bp+4]
push ax
push bx
push dx
sub di,si
push di
call PrintLine
inc si
loop print
pop si
pop di
pop dx
pop cx
pop bx
pop ax
pop bp
ret 10
endp PrintSquare
proc PrintArr
;prints a array
;1.strat of the array(offset)
;2.end of the array (offset)
;output
;none
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push di
push si
mov bx,[bp+6];strat of the array(offset)
mov ax,[bp+4];end of the array (offset)
mov cx,[screen_width]
push 3
push cx
call FindWidthForColAndSpace
pop dx;space widfth
pop di;cooloum width
mov cx,[screen_height]
push cx
push 3
push 1
call FindHeight
pop si;height(dyamnic height *value =pixels)
mov cx,3
xor ax,ax
printar:
    xor ax,ax
    mov al,[byte ptr bx]
    push dx
    xor dx,dx
    mul si
    pop dx
    push ax
    push di
    push 4
    push [plo]
    push [screen_height]
    call PrintSquare
    mov ah,1
    int 21h
    inc bx
    push ax
    mov ax,[plo]
    add ax,dx
    add ax,di
    mov [plo],ax
    pop ax
loop printar
pop si
pop di
pop dx
pop cx
pop bx
pop ax
pop bp
ret 4
endp PrintArr
start:
mov ax, @data
mov ds, ax
mov ax,13h
int 10h
call cls
push 0
push 2
call PrintArr
mov ah,1
int 21h

; push 10
; push 5
; push 4
; push 100
; push 100
; call PrintSquare
; mov ah,86h
; int 15h
;call cls
exit:
    mov ax, 4c00h
    int 21h
END start

推荐答案

Turbo Debugger在加载程序时将一堆寄存器设置为0.当MS-DOS启动时,这些寄存器设置为空.您可以通过添加来获取注册信息为空

Turbo Debugger sets a bunch of registers to 0 when it loads the program. When MS-DOS starts these registers are not set to null. The information which register needs to be null you can achieve by adding

xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
xor si, si
xor di, di
xor bp, bp

在开始过程的开始,并通过逐行将其注释掉.事实证明,欠款是DX.因此,在该寄存器中搜索期望为空的第一个函数或指令.我在FindWidthForColAndSpace的第一条div指令中找到了它.此div执行DX:AX/BX,因此需要DX中的值. xor dx, dx行跟在div之后是否是意外事件?它必须在它的前面.

at the beginning of the start procedure and by commenting it out successively. It will turn out that the delinquent is DX. So search for the first function or instruction which expects a null in this register. I found it in the first div instruction in FindWidthForColAndSpace. This div performs DX:AX/BX and needs therefore a value in DX. Is it an accident that the line xor dx, dx follows the div? It must be in front of it.

这篇关于Assembly(TASM)程序在运行时崩溃,但在调试器(涡轮调试器)中工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:17