【问题标题】:Assembly(tasm) program crashes in run but works fine in debugger(turbo debugger)装配(tasm)程序在运行时崩溃,但在调试器(涡轮调试器)中工作正常
【发布时间】:2017-05-06 10:38:57
【问题描述】:

我的程序(汇编 tasm 16 位)应该为数组打印条形图表示。现在它只支持特定数组,但我会在未来添加对一般情况的支持。代码在调试器中工作正常并将条形打印为expcted.But 在运行中代码被卡住并且不打印任何东西。除了 PrintArr 之外的所有功能都按预期单独工作。我在调试中找不到我的问题,因为问题似乎存在于调试器中。

;
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

【问题讨论】:

  • “我尝试调试它,但没有结束。” 发生了什么?另外,我尝试阅读您的代码,但没有结束,因为它的格式很差,没有缩进或空格。
  • 没有理由有毒。正如我上面提到的,我对代码进行了调试,它运行良好,我的全部问题是代码在 dbeugger 中运行良好,但在运行时崩溃。我是新手如果您对如何更好地格式化我的代码有任何建议,特别是作为一个整体编程和汇编,我将很高兴听到它们。

标签: debugging assembly x86 tasm


【解决方案1】:

Turbo Debugger 在加载程序时将一堆寄存器设置为 0。当 MS-DOS 启动时,这些寄存器设置为空。寄存器需要为空的信息可以通过添加实现

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 后面是不是意外?它必须在它的前面。

【讨论】:

  • 这解决了我的问题。我从来不知道调试器会解决这个问题。我不知道我的问题到底是什么。但是当我知道问题的根源时,我会找到它。非常感谢
猜你喜欢
  • 2015-03-31
  • 2015-03-27
  • 1970-01-01
  • 2019-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多