assembly - Why did mov dx,0 fix this division routine? -


a simple loop find largest divisor, integer of root, in case dropping out @ 5 in 345 triangle

mov ax,3                         mul ax                           push ax                          mov ax,4                         mul ax                           pop bx                           add ax,bx                        push ax    ;save 25 decimal repeated loops                         mov bx,1                         mov bp,sp                         agin                             mov dx,0      ;fixed problem                   mov ax,[bp]   ;25 decimal                   inc bx        ;starts @ 2                   div bx                           cmp bx,ax                        jb agin                           out 

however, weird things happened when program went 2 3, got hex555d instead of 8 (8*3)

putting mov dx,0 in fixed , returned things normal

i have no idea why, no flags changed

anyone know why? signed/unsigned issue?

the div instruction divides number dx:ax operand.

dx upper word. ax lower word. therefore if want divide ax bx, need 0 dx.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -