Re: asm basic calculator
- From: "Wolfgang Kern" <nowhere@xxxxxxxx>
- Date: Sun, 30 Dec 2007 22:24:59 +0100
"bushido" asked:
example
input : 1C2F
output :
+ -
* / mod
hex 4B
-13 ..............................................
dec 75
-19 ..............................................
oct 113
-23 ..............................................
bi 01001011
00-10011 ..............................................
plese , example code
thx.
Now this results are just from ADD: 1C + 2F = 4B (all hex)
and SUB: 1C - 2F = ED (= -13)
If I correct understood your question, ie:(16 bit code yet):
mov ax,[...] ;get input from wherever
"+":
add al,ah
;setc ah ;expand result to ax
"-": ;assuming unsigned values yet
sub al,ah
;setc ah
;neg ah ;expand result sign saturated in ax (also CBW)
"*":
mul ah ;ax=al*ah ;result is 2 bytes in ax
also possible:
imul ah ;same for a signed mul
"/" and "mod":
mov cl,ah
mov ah,0
div cl ;ax/cl: al=quotient ah=remainder = MOD
but it's recommended to expand operands for divide
to avoid any 'result wont fit' divide-exceptions:
movzx cx,ah ;ch=0 cl=ah
xor dx,dx ;clear dx
mov ah,0 ;
div cx ;dx:ax/cx ax=qoutient dx=remainder = MOD
both above are possible with idiv too.
hope this helps, and I'm aware to may have invoked more questions.
Conversion into various output formats may be part of your tool,
but I daubt that signed bytes are used often in calulators ;)
__
wolfgang
.
- References:
- asm basic calculator
- From: bushido
- asm basic calculator
- Prev by Date: Re: asm grep
- Next by Date: Re: Merry Christmas to All.
- Previous by thread: asm basic calculator
- Index(es):
Relevant Pages
|