Here is a partial list of OpCodes for a simple computer (like MARIE): Write an A
ID: 3821160 • Letter: H
Question
Here is a partial list of OpCodes for a simple computer (like MARIE): Write an Assembly Language program that calculates powers of 2 and stores them in memory. It should calculate and store powers of 2 from 2^0 to 2^10. Your Assembly Language instructions should start at address 100 (in Hex) and your Data should start at address 900 (in Hex) where 0001 (in Hex) should be stored. Your last instruction should Halt program execution. In other words your program should start out with this. 100 Load 900 101 Add 900 102 Store 901 900 0001 901 0000Explanation / Answer
you should have noticed that:
20 = 1 = 0001
21 = 2 = 0010
22 = 4 = 0100
23 = 8 = 1000
...
So to achive the 2n we need to double the last 2n-1, but since we dont have multiplication operator, we will add the 2n-1 twice to calculate 2n
100 load 900 0001 1001 0000 0000
101 Add 900 0011 1001 0000 0000
102 Store 901 0010 1001 0000 0001
103 Add 901 0011 1001 0000 0001
104 Store 902 0010 1001 0000 0010
105 Add 902 0011 1001 0000 0010
106 Store 903 0010 1001 0000 0011
107 Add 903 0011 1001 0000 0011
108 Store 904 0010 1001 0000 0100
109 Add 904 0011 1001 0000 0100
110 Store 905 0010 1001 0000 0101
111 Add 905 0011 1001 0000 0101
112 Store 906 0010 1001 0000 0110
113 Add 906 0011 1001 0000 0110
114 Store 907 0010 1001 0000 0111
115 Add 907 0011 1001 0000 0111
116 Store 908 0010 1001 0000 1000
117 Add 908 0011 1001 0000 1000
118 Store 909 0010 1001 0000 1001
119 Halt 0111
I hope you liked the approach and explanation. If incase you have any doubt with the approach, please comment below. I shall be happy to help you with the logic of the code.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.