Re: asm basic calculator




"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



.



Relevant Pages

  • Re: Floating point exception
    ... mov eax,3 ... You need to convert this string og ascii characters to a number before you can do arithmetic on it (with the exception of the divide by ten "cheat" I mentioned). ... Get first/next character. ... Convert from ascii digit to number. ...
    (comp.lang.asm.x86)
  • Re: [PATCH] SLAB : use a multiply instead of a divide in obj_to_index()
    ... When some objects are allocated by one CPU but freed by another CPU we can ... divide took 1.20 % of CPU_CLK_UNHALTED events in kernel. ... mov %eax,// could be avoided ... if (flags & SLAB_CACHE_DMA) ...
    (Linux-Kernel)
  • Re: itoa assembly version
    ... mov byte ptr ds:, dl ... cmp ax, 0; or "test ax, ax" ... the cause of "Divide Overflow" ... zero at startup in an .exe, ...
    (alt.lang.asm)
  • Re: Floating point exception
    ... >mov edx,leninput;2;leninput ... This reads two characters from stdin and stores them at varinput, in ASCII. ... Now you take 12,337 and try to divide by 10. ... Now you can store ax into a string for printing. ...
    (comp.lang.asm.x86)
  • Re: printing 2 and 3 digit numbers in masm
    ... instances of "mov ah,9" in the code you posted. ... So, if al contains 08, cbw will produce ax=0008. ... instruction is UNSIGNED. ... you get a divide overflow. ...
    (comp.lang.asm.x86)