1

How can I collect the remainders of a div instruction into a register so that it can be converted into a string and displayed to the console. For example:

.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
  adrs1 dd 0
  adrs2 dd 0
.code
start:
  mov eax, 6        ; add 6 to eax
  mov ebx, 7        ; add 7 to ebx
  imul eax, ebx     ; multiply both numbers, result is in eax
  mov ecx, 10       ; add 10 to ecx
  idiv eax:ecx, edx ; divide eax (result of mul) by 10 so that I can separate the              digits into single characters so  I can display them.
                    ; Numbers will be 4 and 2. Is the result of the division stored in EDX?
  mov adrs1, eax      ; mov the '4' from the '42' result of the multiplication into 'adrs'
  mov adrs2, edx      ; mov the remainder of the division to adrs2
  add adrs1, 50       ; make the result the correct ASCII character for the result
  add adrs2, 50       ; " "
  invoke StdOut, addr adrs1 ; display adrs1
  invoke StdOut, addr adrs2 ; display adrs2
  invoke ExitProcess, 0 ; exit
end start

I need to display the remainders of the division. Any help would be greatly appreciated.

Thanks in advance,

Progrmr

5
  • possible duplicate of How to implement the mod operator in assembly May 13, 2012 at 9:57
  • Thanks, but is that code implementable in MASM?
    – Progrmr
    May 13, 2012 at 12:23
  • Doing an IDIV leaves quotient and remainders in registers... so you don't have to "do" anything to get the remainder into a register. What's the source of your question?
    – Ira Baxter
    May 15, 2012 at 11:35
  • I'm trying to separate a number (e.g. 1405) into separate digits (that's why I want the remainder, because I'm dividing by 10 to separate the digits past the decimal point) so that I can print them to the console.
    – Progrmr
    May 16, 2012 at 4:17
  • 1
    @Progrmr The remainder of a div instruction goes into edx. BTW why don't you use the BCD features of the x86?
    – Powerslave
    Apr 17, 2013 at 9:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.