How to keep negative numbers in assembly language TASM ? x86 -


;i have problem , should solve given numbers pls help!!! ;13. (a+b+c*d)/(9-a) ;a,c,d-byte; b-doubleword

assume cs:code,   ds:data  data segment 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, 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, cbw mov bl,9   ## cbw conversion al -> ax   ## cbw/cwd instructions influence ax   ## register. not possible use cbw   ## bx register!   ##   ## btw: value of bh part of bx   ## register undefined here! cbw sub bx,ax mov res1, ax mov al, c cbw   ## mul unsigned multiplication!   ## imul signed one! mul d mov cl,a   ## again try use cbw register   ## ax -> destroy ax   ## register! cbw add ax,cx   ## because "add ax,cx" may generate carry   ## you'll have "adc dx, 0" here! mov bx, word ptr b mov cx, word ptr b+2 add bx, ax adc cx, dx   ## why didn't "add ax, bx" ,   ## "adc dx, cx" - not need next   ## 2 instructions in case?   ## (however not real error.) mov ax, bx mov dx, cx   ## instruction useless   ## unless use "(i)div cx" below! mov cx, res1   ## why do "cwd" here?   ## high 16 bits of 32-bit word "b"   ## lost when doing so!   ##   ## operations on "dx" register above   ## useless when doing here! cwd   ## "div" unsigned division.   ## signed division use "idiv" div res1 mov finalres, ax 

i'm not sure if found mistakes in code.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -