-
September 27th, 2005, 11:04 AM
#1
Division
I guys. New to assembly. I have listed my code below an the code solves the folowing problem. A*B -(A+B)/ (A-B). My code works until i get to the division part. Any suggestions would be very helpful. Thanks for reading!
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCodeWORD
INCLUDE io.h ; file for input/output
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed character
.STACK 4096 ; 4096-byte stack is reserved
.DATA ; storage for data reserved
numberA DWORD ?
numberB DWORD ?
promptA BYTE "Enter first number: ", 0
promptB BYTE "Enter second number: ", 0
string BYTE 40 DUP (?)
result BYTE cr, Lf, "The answer is "
answer BYTE 11 DUP (?)
BYTE cr, Lf, 0
.CODE ; beginning of main program code
_start:
output promptA ; prompts for the 1st number
input string, 40 ; reads ASCII characters
atod string ; converts to integer
mov numberA, eax ; stores 1st number (A) in memory
output promptB ; prompts for the 2nd number
input string, 40 ; reads ASCII characters
atod string ; converts to integer
mov numberB, eax ; adds 2nd number to the 1st (A+B)
mov eax, numberA ; puts 1st number in eax register (A)
add eax, numberB ; adds 2nd number to the first (A+B)
mov ebx, numberA ; puts 1st number in ebx register
imul ebx, numberB ; multiplies 2nd and 1st number together
sub ebx, eax ; subtracts (A+B) from (A*B)
mov ecx, numberA ; puts 1st number in ecx register
sub ecx, numberB ; subtracts 2nd number from 1st number (A-B)
cwd ; preparing the divisor
idiv ecx ; dividing by (A-B)
dtoa answer, ebx ; converts to ASCII characters
output result ; outputs result label and answer to problem
INVOKE ExitProcess, 0 ; exits with return code 0
PUBLIC _start ; make entry point public
END ; end of code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|