News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Arithmetic Operations in Assmebly

Started by rodolfolopes, September 28, 2014, 10:54:30 AM

Previous topic - Next topic

rodolfolopes

Hi there guys

Thanks a lot for accepting me in this forum. Im really new into assemby languaje I just finished my first program in assembly and it was about show a string in screen. But now my teacher just killed and  I really would like to know if you can help me to make this operations:

7-2
10-5-1
5*6
2*157
15/3
15367/8


Are those really hard?

Thanks a lot

jj2007

Quote from: rodolfolopes on September 28, 2014, 10:54:30 AMBut now my teacher just killed

Don't do that again :eusa_naughty:

QuoteAre those really hard?

No, not really:

include \masm32\include\masm32rt.inc

.data?
MyDouble   REAL8 ?

.code
start:
   print str$(7-2), 9, "assembly time 7-2", 13, 10

   mov eax, 7
   sub eax, 2
   print str$(eax), 9, "runtime 7-2", 13, 10

   mov eax, 2
   imul eax, eax, 157
   print str$(eax), 9, "runtime 2*157", 13, 10

   mov eax, 15
   cdq      ; see \Masm32\Help\Opcodes.chm
   mov ecx, 3
   idiv ecx
   print str$(eax), 9, "runtime 15/3", 13, 10

   mov eax, 15367
   cdq      ; see \Masm32\Help\Opcodes.chm
   mov ecx, 8
   idiv ecx
   print str$(eax), 9, "runtime 15367/8, int", 13, 10

   push 15367
   fild dword ptr [esp]
   push 8
   fild dword ptr [esp]
   fdiv
   fstp MyDouble
   printf("%.2f\truntime 15367/8, float", MyDouble)
   inkey "OK?"
   fstp st  ; cleanup your FPU
   exit

end start


Output:
5       assembly time 7-2
5       runtime 7-2
314     runtime 2*157
5       runtime 15/3
1920    runtime 15367/8, int
1920.88 runtime 15367/8, float


Unzip attachment, open *.asm in \Masm32\qEditor.exe, Console build all

dedndave

#2
the code you want depends on the teacher - lol
has he told you to use Kip Irvine library? (Kip Irvine, Author)

if so, he wants you to use Kip's floating point routines

Gunther

Quote from: jj2007 on September 28, 2014, 11:31:18 AM
Don't do that again :eusa_naughty:

I think he doesn't kill his teacher. And welcome to the forum Rodolfo.

Gunther
You have to know the facts before you can distort them.