Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Example assembly language program -- adds two numbers
- ; Author: Chris Johnson
- ; Date: 10/14/11
- .586
- .MODEL FLAT
- INCLUDE io.h ; header file for input/output
- .STACK 4096
- .DATA
- Pennies DWORD ?
- Nickels DWORD ?
- Dimes DWORD ?
- Quarters DWORD ?
- HalfD DWORD ?
- Dollars DWORD ?
- promptPennies BYTE "Enter amount of Pennies", 0
- promptNickels BYTE "Enter amount of Nickels", 0
- promptDimes BYTE "Enter amount of Dimes", 0
- promptQuarters BYTE "Enter amount of Quarters", 0
- promptHalfD BYTE "Enter amount of HalfDollars", 0
- promptDollars BYTE "Enter amount of Dollars", 0
- string BYTE 40 DUP (?)
- resultLbl BYTE "Coin Information", 0
- StringOutputOne BYTE "Number of Coins: "
- rlNumberCoins BYTE
- sum BYTE 11 DUP(?), 0
- NumberOfDollars BYTE "Dollars: ", 0
- NumberOfCents BYTE "Cents: ", 0
- .CODE
- _MainProc PROC
- input promptPennies, string, 40 ; read ASCII characters
- atod string ; convert to integer
- mov Pennies, eax ; store in memory
- input promptNickels, string, 40 ; repeat for second number
- atod string ;convert to integer
- mov Nickels, eax ;store in memory
- input promptDimes, string, 40 ; third number being read in
- atod string ;convert to integer
- mov Dimes, eax ;store in memory
- input promptQuarters, string, 40 ; third number being read in
- atod string ;convert to integer
- mov Quarters, eax ;store in memory
- input promptHalfD, string, 40 ; third number being read in
- atod string ;convert to integer
- mov HalfD, eax ;store in memory
- input promptDollars, string, 40 ; third number being read in
- atod string ;convert to integer
- mov Dollars, eax ;store in memory
- mov edx, 5 ; move 5 to edx
- mov eax, Nickels ; move amount of Nickels to eax
- mul edx ; multiply 5 times eax
- add eax, Pennies ; add amount of pennies to eax
- mov ecx, eax ; store in ecx
- mov edx, 10 ; move 10 to edx
- mov eax, Dimes ; move amount of Dimes to eax
- mul edx ; multiply 10 times eax
- add ecx, eax ; add the value of eax to ecx
- mov edx, 25 ; move 25 to edx
- mov eax, Quarters ; move amount of Quarters to eax
- mul edx ; multiply 25 times eax
- add ecx, eax ; add the value of eax to ecx
- mov edx, 50 ; move 50 to edx
- mov eax, HalfD ; move amount of HalfDollars to eax
- mul edx ; multiply 50 times eax
- add ecx, eax ; add the value of eax to ecx
- mov edx, 100 ; move 100 to edx
- mov eax, Dollars ; move amount of Dollars to eax
- mul edx ; multiply 100 times eax
- add ecx, eax ; add value of eax to ecx
- mov edx, 0 ; clear the value for division
- mov eax, ecx ; move the value of ecx to eax
- mov ebx, 100 ; move 100 to ebx
- div ebx ; div eax by ebx
- mov ecx, eax ; store the value in ecx
- mov ebx, Pennies ; move amount of Pennies to ebx
- add ebx, Nickels ; add amount of Nickels to ebx
- add ebx, Dimes ; add amount of Dimes to ebx
- add ebx, Quarters ; add amount of Quarters to ebx
- add ebx, HalfD ; add amount of HalfDollars to ebx
- add ebx, Dollars ; add amount of Dollars to ebx
- dtoa sum, ebx ; convert to ASCII characters
- dtoa NumberOfDollars, ecx ; convert to ASCII characters
- dtoa NumberOfCents, edx ; convert to ASCII characters
- output resultLbl, StringOutputOne ; output label and sum
- mov eax, 0 ; exit with return code 0
- ret
- _MainProc ENDP
- END ; end of source code
Add Comment
Please, Sign In to add comment