Ok I have an assignment that requires me to create 3 macros to do 3 different function. I have the first one completed but the 2nd two are giving me some trouble.

#2) Write a macro that takes in 2 32-bit integers and divides the first from the second and lists the remainder (if any).

Here is the macro I currently have:

mDIV MACRO text
	.data
		Dvalue DWORD ?
		Dvalue2 DWORD ?
		
		prompt3 BYTE "Enter your first Integer: ",0
		prompt4 BYTE "Enter your second Integer: ",0
		prompt5 BYTE "Answer: ",0
	.code
		mov edx, OFFSET prompt3
		call WriteString
		call ReadDec
		mov eax, 12
		call Crlf
		
		mov edx, OFFSET prompt4
		call WriteString
		call ReadDec 
		mov ebx, 6
		call Crlf
		
		div bl
		mov edx, OFFSET prompt5
		call WriteString
		call WriteDec
		call Crlf
		call WaitMsg
ENDM

Currently I just place values in EAX & EBX to ensure it works. But when I change it to:

mov Dvalue, eax

mov Dvalue2, ebx

The program crashes. Any idea why?


Now for the 3rd macro:

#3 Take a character input and output it's ASCII value, on this one I have no clue on how to do it. My book does mention using "aaa" to convert it but when I do that all I get is 0, which last I checked wasn't the ASCII value of every single character. Only code I have for this one currently is just the input portion so I see no need to place it up.

Ok I managed to get the division portion working sort of (it isn't handling remainders, but whatever too tired to care).

Here is the new code for that macro

mDIV MACRO text
	.data
		Dvalue1 DWORD ?
		Dvalue2 DWORD ?
		Dvalue3 DWORD ?
		
		prompt3 BYTE "Enter your first Integer: ",0
		prompt4 BYTE "Enter your second Integer: ",0
		prompt5 BYTE "Answer: ",0
	.code
		mov edx, OFFSET prompt3
		call WriteString
		call ReadInt
		mov Dvalue1, eax
		
		mov edx, OFFSET prompt4
		call WriteString
		call ReadInt
		mov Dvalue2, eax
		mov eax, Dvalue1
		mov ebx, Dvalue2

		div bl
		mov Dvalue3, eax
		mov edx, OFFSET prompt5
		call WriteInt
		call Crlf
		call WaitMsg
ENDM

Now all I need help with is the ASCII portion, unless someone can tell me how to get the remainders working in the above macro

This article has been dead for over six months. Start a new discussion instead.