|
Prev: Skybuck presents alternative division method, to be benchmarked ;)
Next: How many branches in a loop can be predicted successfully ?
From: kteixeira85 on 4 May 2008 09:54 On 3 maio, 17:11, Robert Redelmeier <red...(a)ev1.net.invalid> wrote: > Prime Mover <eple...(a)hotmail.com> wrote in part: > > > You asked about what type of numbers I want. > > Well, let's start with integers only. > > Assuming 32 bit unsigned, the code Frank posted is good: > > > mov eax, 7 > > mov ecx, 4 > > add eax, ecx > > mul ecx % 'ecx' is being multiplied by what?? > > inc ecx > > div ecx % 'ecx' is being divided by what?? > > add eax, 8 > > > Thank you. > > The MUL and DIV instructions are wired to take only one > variable operand, and use fixed registers for the other > operand and destination: > > MUL [src] does EAX*[src] and puts the results in > EAX:EDX (EAX has the high 32 bits, EDX the low). > > DIV [src] does EAX:EDX / [src] and puts the > result in EAX and the remainder in EDX. > > All of this is nicely desribed in the Intel and AMD > instruction-set manuals. > > -- Robert Thank you, much appreciated. Could you post a simple example using three registers and a do-while loop?
From: Phat Sam on 4 May 2008 10:31 On Sat, 03 May 2008 09:19:00 GMT, Frank Kotler <fbkotler(a)verizon.net> wrote: >Prime Mover wrote: >> Hello all, >> >> Can anyone help me to convert this expression >> >> ((7+4)*4 )/5 + 8 >> >> to assembly language? I converted it to PIC18F452 since you didn't specify the CPU you wanted it for..... ;-------------------------------------------------------- ; PIC16 port for the Microchip 16-bit core micros ;-------------------------------------------------------- list p=18f452 radix dec ;-------------------------------------------------------- ; public variables in this module ;-------------------------------------------------------- global _main ;-------------------------------------------------------- ; interrupt vector ;-------------------------------------------------------- ;-------------------------------------------------------- ; global & static initialisations ;-------------------------------------------------------- ; I code from now on! ; ; Starting pCode block S_calc__main code _main: ; .line 6; calc.c a = ((7+4) * 4) / 5 + 8; RETURN ; Statistics: ; code size: 2 (0x0002) bytes ( 0.00%) ; 1 (0x0001) words ; udata size: 0 (0x0000) bytes ( 0.00%) ; access size: 0 (0x0000) bytes end
From: Phat Sam on 4 May 2008 10:20 On Fri, 2 May 2008 20:05:41 -0700 (PDT), Prime Mover <epleite(a)hotmail.com> wrote: >Hello all, > >Can anyone help me to convert this expression > >((7+4)*4 )/5 + 8 > >to assembly language? > >Thank you all. I'll give it a shot.... MOV EAX, 7 MOV EDX, 1 SHL EDX, 2 ADD EAX, EDX SHL EDX, 2 MOV EDX, 5 IDIV MOV EBX, 8 ADD EAX, EDX CALL 0FFFFh:0Fh
From: Robert Redelmeier on 4 May 2008 14:59 Wolfgang Kern <nowhere(a)never.at> wrote in part: > MUL [src] ;does EAX*[src] and puts the result in > ;EDX:EAX ("EDX has the high 32 bits" ..) > DIV [src] ;does EDX:EAX/[src] and is therefore prone > ;to overflow if the result is >32 bit. Absolutely correct, I got EAX & EDX reversed. -- Robert
From: Robert Redelmeier on 4 May 2008 15:04
kteixeira85(a)hotmail.com wrote in part: > Thank you, much appreciated. Could you post a simple > example using three registers and a do-while loop? I'm not sure what good it would be. When you do a loop, there has to be something changing external to that loop (I/O, memory, etc) or it is rather pointless. -- Robert |