2014-11-19 3 views
0

; У меня есть эта проблема, и я должен решить ее с указанными числами, кто-нибудь поможет !!! ; 13. (a + b + c * d)/(9-a) ; a, c, d-байт; б-двойноеКак сохранить отрицательные числа на языке ассемблера TASM? x86

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 
+0

Что именно вы хотите достичь и что получилось в результате вашей текущей программы? – SBH

+0

_ «У меня есть эта проблема» _. Какая проблема? Вам нужно добавить более подробное описание, например. каковы ваши ожидаемые и фактические результаты. – Michael

+0

Я должен решить эту проблему (a + b + c * d)/(9-a) –

ответ

0

Ваш код содержит несколько ошибок:

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 

Я не уверен, если я нашел все ошибки в коде.

+0

Спасибо за ответ, теперь я вижу некоторые вещи яснее! –

Смежные вопросы