Vintage1983
November 17th, 2006, 04:42 AM
I am in my first semester of assembly on the intel 86x processor, basicly I have been working on this problem for about two weeks and my book and net references haven't been able to help me out.
I am doing a call from C++ into Assembly from this code.
enum ResultCode {ShowSquare, ShowMultiply, ShowDivide, ShowRemainder, ShowDivideFailure};
enum SuccessCode {Failure, Success};
extern "C" SuccessCode Divide (long, long, long &, long &);
extern "C" void PrintResult (ResultCode, long);
...some code...main....
cout << "Enter mumber to divide into then number to divide by" << endl;
cin >> Num1 >> Num2;
if (Divide (Num1, Num2, Result, Remainder) == Success)
cout << "Result is " << Result << " and remainder is " << Remainder << endl<<endl;
else
cout << "Attempted division by zero" << endl<<endl;
...
void PrintResult (ResultCode PrintCode, long Value)
{
switch (PrintCode)
{
case ShowDivide:
cout << "Display of divide is " << Value << endl;
break;
case ShowRemainder:
cout << "Display of remainder is " << Value << endl;
break;
case ShowDivideFailure:
cout << "Display of Division by zero" << endl;
break;
I have most of the Assembly code up and working but I can't figure out how to modify the result and remainded parameters being passed into the Assembly call after the result and such has been found in my .asm file.
Here is a snippet of my Assembly code
;_Divide proc dividend:DWORD, divsor:DWORD, result:DWORD, remained:DWORD
_Divide proc
push ebp
mov ebp, esp
; mov eax, dividend
; mov eax, divsor
; mov eax, result
; mov eax, remained
; jmp L2
mov ecx, [ebp + 12] ; num1 dividend
mov eax, [ebp + 8] ; num2 divisor
; cwd
; mov edx, eax
; mov eax, ecx
; cwd
; mov edx, ebx
; mov ecx, eax
; mov eax, ebx
cmp ecx, 0
jne DividFunc
push 0
push 5
call _PrintResult
pop eax
pop eax
mov eax, 0
jmp L2
DividFunc:
sub edx, edx
idiv ecx ; product should be in eax
cmp edx, 0
jne L1
push edx
push eax
push eax
push 2
call _PrintResult
pop eax
pop eax
pop eax
pop edx
; mov dword ptr [ebp+16], eax
; mov dword ptr [ebp+20], edx
; mov ebx, dword ptr [ebp+16]
; mov ecx, dword ptr [ebp+20]
; mov ebx, eax
; mov ecx, edx
mov eax, 1
jmp L2
L1:
push edx
push eax
push 0
push 3
call _PrintResult
pop eax
pop eax
pop eax
pop edx
mov eax, 1
L2:
pop ebp
ret
_Divide endp
My results when I run is;
Enter mumber to divide into then number to divide by
250
25
Display of divide is 10
Result is 200 and remainder is -858993460
As you can see I've tried a number of different things since what logically I think should work hasn't...I would think that I should be able to reference the position [ebp+16] & [ebp+20] and do a mov into it. Any clarification would be greatly appreciated!
I am doing a call from C++ into Assembly from this code.
enum ResultCode {ShowSquare, ShowMultiply, ShowDivide, ShowRemainder, ShowDivideFailure};
enum SuccessCode {Failure, Success};
extern "C" SuccessCode Divide (long, long, long &, long &);
extern "C" void PrintResult (ResultCode, long);
...some code...main....
cout << "Enter mumber to divide into then number to divide by" << endl;
cin >> Num1 >> Num2;
if (Divide (Num1, Num2, Result, Remainder) == Success)
cout << "Result is " << Result << " and remainder is " << Remainder << endl<<endl;
else
cout << "Attempted division by zero" << endl<<endl;
...
void PrintResult (ResultCode PrintCode, long Value)
{
switch (PrintCode)
{
case ShowDivide:
cout << "Display of divide is " << Value << endl;
break;
case ShowRemainder:
cout << "Display of remainder is " << Value << endl;
break;
case ShowDivideFailure:
cout << "Display of Division by zero" << endl;
break;
I have most of the Assembly code up and working but I can't figure out how to modify the result and remainded parameters being passed into the Assembly call after the result and such has been found in my .asm file.
Here is a snippet of my Assembly code
;_Divide proc dividend:DWORD, divsor:DWORD, result:DWORD, remained:DWORD
_Divide proc
push ebp
mov ebp, esp
; mov eax, dividend
; mov eax, divsor
; mov eax, result
; mov eax, remained
; jmp L2
mov ecx, [ebp + 12] ; num1 dividend
mov eax, [ebp + 8] ; num2 divisor
; cwd
; mov edx, eax
; mov eax, ecx
; cwd
; mov edx, ebx
; mov ecx, eax
; mov eax, ebx
cmp ecx, 0
jne DividFunc
push 0
push 5
call _PrintResult
pop eax
pop eax
mov eax, 0
jmp L2
DividFunc:
sub edx, edx
idiv ecx ; product should be in eax
cmp edx, 0
jne L1
push edx
push eax
push eax
push 2
call _PrintResult
pop eax
pop eax
pop eax
pop edx
; mov dword ptr [ebp+16], eax
; mov dword ptr [ebp+20], edx
; mov ebx, dword ptr [ebp+16]
; mov ecx, dword ptr [ebp+20]
; mov ebx, eax
; mov ecx, edx
mov eax, 1
jmp L2
L1:
push edx
push eax
push 0
push 3
call _PrintResult
pop eax
pop eax
pop eax
pop edx
mov eax, 1
L2:
pop ebp
ret
_Divide endp
My results when I run is;
Enter mumber to divide into then number to divide by
250
25
Display of divide is 10
Result is 200 and remainder is -858993460
As you can see I've tried a number of different things since what logically I think should work hasn't...I would think that I should be able to reference the position [ebp+16] & [ebp+20] and do a mov into it. Any clarification would be greatly appreciated!