简体   繁体   English

如何用汇编语言TASM保持负数? x86

[英]How to keep negative numbers in assembly language TASM ? x86

;I have this problem and I should solve it with the given numbers pls somebody help!!! ;我有这个问题,我应该用给定的数字解决,请有人帮忙!!! ;13. ; 13。 (a+b+c*d)/(9-a) ;a,c,d-byte; (a + b + c * d)/(9-a); a,c,d字节; b-doubleword b-双字

ASSUME cs:code, 

ds:data

DATA SEGMENT
a db 11
b dd 1
c db -2
d db 2

res1 dw ?
finalres dw ?

data ends

code segment 

start:

mov ax, data
mov ds, ax

mov al, a
cbw
mov bl,9
cbw
sub bx,ax
mov res1, ax

mov al, c
cbw
mul d
mov cl,a
cbw
add ax,cx

mov bx, word ptr b
mov cx, word ptr b+2
add bx, ax
adc cx, dx
mov ax, bx
mov dx ,cx
mov cx, res1
cwd
div res1
mov finalres, ax

mov ax, 4C00h
int 21h

code ends

end start

Your code contains multiple errors: 您的代码包含多个错误:

mov al, a
cbw
mov bl,9
  ## This cbw will do a conversion AL -> AX
  ## cbw/cwd instructions always influence the AX
  ## register. It is not possible to use cbw for
  ## the BX register!
  ##
  ## BTW: The value of the BH part of the BX
  ## register is undefined here!
cbw
sub bx,ax
mov res1, ax
mov al, c
cbw
  ## Mul is an unsigned multiplication!
  ## Imul would do a signed one!
mul d
mov cl,a
  ## Again you try to use cbw for another register
  ## than AX -> This will only destroy the AX
  ## register!
cbw
add ax,cx
  ## Because the "add ax,cx" may generate a carry
  ## you'll have to do an "adc dx, 0" here!
mov bx, word ptr b
mov cx, word ptr b+2
add bx, ax
adc cx, dx
  ## Why didn't you do an "add ax, bx" and an
  ## "adc dx, cx" - you would not need the next
  ## two instructions in this case?
  ## (However this is not a real error.)
mov ax, bx
mov dx, cx
  ## This instruction is useless
  ## unless you use "(i)div cx" below!
mov cx, res1
  ## Why do you do this "cwd" here?
  ## The high 16 bits of the 32-bit word "b"
  ## will get lost when doing so!
  ##
  ## All operations on the "dx" register above
  ## are also useless when doing this here!
cwd
  ## "div" will do an unsigned division. For a
  ## signed division use "idiv"
div res1
mov finalres, ax

I'm not sure if I found all mistakes in your code. 我不确定是否在您的代码中发现了所有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM