Guest User

Untitled

a guest
Jan 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. ; Example assembly language program -- adds two numbers
  2. ; Author: Chris Johnson
  3. ; Date: 10/14/11
  4.  
  5. .586
  6. .MODEL FLAT
  7.  
  8. INCLUDE io.h ; header file for input/output
  9.  
  10. .STACK 4096
  11.  
  12. .DATA
  13. Pennies DWORD ?
  14. Nickels DWORD ?
  15. Dimes DWORD ?
  16. Quarters DWORD ?
  17. HalfD DWORD ?
  18. Dollars DWORD ?
  19. promptPennies BYTE "Enter amount of Pennies", 0
  20. promptNickels BYTE "Enter amount of Nickels", 0
  21. promptDimes BYTE "Enter amount of Dimes", 0
  22. promptQuarters BYTE "Enter amount of Quarters", 0
  23. promptHalfD BYTE "Enter amount of HalfDollars", 0
  24. promptDollars BYTE "Enter amount of Dollars", 0
  25.  
  26. string BYTE 40 DUP (?)
  27. resultLbl BYTE "Coin Information", 0
  28. StringOutputOne BYTE "Number of Coins: "
  29. rlNumberCoins BYTE
  30. sum BYTE 11 DUP(?), 0
  31. NumberOfDollars BYTE "Dollars: ", 0
  32. NumberOfCents BYTE "Cents: ", 0
  33.  
  34. .CODE
  35. _MainProc PROC
  36. input promptPennies, string, 40 ; read ASCII characters
  37. atod string ; convert to integer
  38. mov Pennies, eax ; store in memory
  39.  
  40. input promptNickels, string, 40 ; repeat for second number
  41. atod string ;convert to integer
  42. mov Nickels, eax ;store in memory
  43.  
  44. input promptDimes, string, 40 ; third number being read in
  45. atod string ;convert to integer
  46. mov Dimes, eax ;store in memory
  47.  
  48. input promptQuarters, string, 40 ; third number being read in
  49. atod string ;convert to integer
  50. mov Quarters, eax ;store in memory
  51.  
  52. input promptHalfD, string, 40 ; third number being read in
  53. atod string ;convert to integer
  54. mov HalfD, eax ;store in memory
  55.  
  56. input promptDollars, string, 40 ; third number being read in
  57. atod string ;convert to integer
  58. mov Dollars, eax ;store in memory
  59.  
  60. mov edx, 5 ; move 5 to edx
  61. mov eax, Nickels ; move amount of Nickels to eax
  62. mul edx ; multiply 5 times eax
  63. add eax, Pennies ; add amount of pennies to eax
  64. mov ecx, eax ; store in ecx
  65.  
  66. mov edx, 10 ; move 10 to edx
  67. mov eax, Dimes ; move amount of Dimes to eax
  68. mul edx ; multiply 10 times eax
  69. add ecx, eax ; add the value of eax to ecx
  70.  
  71. mov edx, 25 ; move 25 to edx
  72. mov eax, Quarters ; move amount of Quarters to eax
  73. mul edx ; multiply 25 times eax
  74. add ecx, eax ; add the value of eax to ecx
  75.  
  76. mov edx, 50 ; move 50 to edx
  77. mov eax, HalfD ; move amount of HalfDollars to eax
  78. mul edx ; multiply 50 times eax
  79. add ecx, eax ; add the value of eax to ecx
  80.  
  81. mov edx, 100 ; move 100 to edx
  82. mov eax, Dollars ; move amount of Dollars to eax
  83. mul edx ; multiply 100 times eax
  84. add ecx, eax ; add value of eax to ecx
  85. mov edx, 0 ; clear the value for division
  86.  
  87. mov eax, ecx ; move the value of ecx to eax
  88. mov ebx, 100 ; move 100 to ebx
  89. div ebx ; div eax by ebx
  90. mov ecx, eax ; store the value in ecx
  91.  
  92. mov ebx, Pennies ; move amount of Pennies to ebx
  93. add ebx, Nickels ; add amount of Nickels to ebx
  94. add ebx, Dimes ; add amount of Dimes to ebx
  95. add ebx, Quarters ; add amount of Quarters to ebx
  96. add ebx, HalfD ; add amount of HalfDollars to ebx
  97. add ebx, Dollars ; add amount of Dollars to ebx
  98.  
  99. dtoa sum, ebx ; convert to ASCII characters
  100. dtoa NumberOfDollars, ecx ; convert to ASCII characters
  101. dtoa NumberOfCents, edx ; convert to ASCII characters
  102. output resultLbl, StringOutputOne ; output label and sum
  103.  
  104. mov eax, 0 ; exit with return code 0
  105. ret
  106. _MainProc ENDP
  107. END ; end of source code
Add Comment
Please, Sign In to add comment