flat assembler
Message board for the users of flat assembler.
Index
> Main > unsigned divide, round up? |
Author |
|
edfed 08 Feb 2011, 13:21
div 16
cmp dx,0 je @f inc ax @@: mov dx,ax and dx,0fh je @f add ax,16 @@: shr ax,4 |
|||
08 Feb 2011, 13:21 |
|
revolution 08 Feb 2011, 13:46
Add 15 to your numerator.
Code: mov eax,[myvalue] add eax,15 shr eax,4 mov [myresult],eax |
|||
08 Feb 2011, 13:46 |
|
edfed 08 Feb 2011, 14:12
no jcc, cool!!! |
|||
08 Feb 2011, 14:12 |
|
b1528932 08 Feb 2011, 20:47
So it needs to be 8086 code, so no shr using imm8 there. and no eAX
considering that you divide only by 16: ;ax = input test ax, 0x000F mov cl, 4 ror ax, cl adc ax, 0 and ax, 0x0FFF ;ax = output |
|||
08 Feb 2011, 20:47 |
|
Hrstka 14 Feb 2011, 20:12
My favourite way for rounding up:
Code: neg ax and ax, -16 ; round up to next paragraph neg ax I'm not sure if the neg instruction exists on 8086, but neg ax can be replaced with Code: xor ax, -1 ; = not ax inc ax EDIT: I overlooked the div part, in this case use revolution's way. If shr ax, imm8 is not allowed, Code: mov cl, 4 shr ax, cl |
|||
14 Feb 2011, 20:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.