News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to write code if right most bit is equal to 1?

Started by scooter4483, February 07, 2006, 09:06:17 PM

Previous topic - Next topic

ramguru

I guess "then" means after all iterations, and EBX should be 0, EAX something big, ECX - product (result). This means that you really miswrite ...

EduardoS

His code is ok, just don't preserve the registers,
To preserve registers i prefer push/pop, if not possible then save to somewhere in memory if not possible too you need to make another proc...
With loops there is one way (i mean, one way better than add eax to ecx ebx times) to do it modifying only two registers (the counter and the result), without loop you just need to modify the result, now think how to do it, it's your homework not mine :8)

MichaelW

FWIW the Irvine32 library with full source code is available (apparently from the author) here:

http://www.nuvisionmiami.com/books/asm/examples/index.htm

It is a beta version, but the DumpRegs procedure and the macros it depends on are essentially unchanged from the earlier non-beta version.
eschew obfuscation

dsouza123


.data
  holdeax dd 0
  holdebx dd 0

.code
  mov eax, 5
  mov ebx, 6
  mov ecx, 0

  mov holdeax, eax  ; store starting values of eax and ebx for later
  mov holdebx, ebx

  cmp ebx, 0
  jz  iszero
again:
    test ebx, 1
    jz  skip
    add ecx, eax
skip:
    shl eax, 1
    shr ebx, 1
    jnz again
iszero:
  mov eax, holdeax  ; restore starting eax and ebx
  mov ebx, holdebx
  ; ecx has the part of the answer that fits in one dword

scooter4483

yeah, the teacher said i could push and pop onto edi and esi.  how do implement that?  thanks.

EduardoS

To save in edi and esi simple mov:

mov edi, eax
mov esi, ebx
...
...
...
mov eax, edi
mov ebx, esi

BogdanOntanu

And take care: the rules here state that we do not make other people's homework:D
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro