admin管理员组文章数量:1431145
Example: if the entered value is 5, the values 5,6,7,8,9,10 (one number per line) will be displayed followed by the number of iterations. Note that the number 10 should be displayed.
I tried many things but the loop doesn't stop , it keep going after 10
ORG 400 / Start at adress 400
INPUT / Take a number from the user
STORE X / Store INPUT in memory location X
LOAD ONE / Load the constant value 1
STORE Counter / Store it in the Counter Memory location
LOOP, LOAD X / Load the value of X
OUTPUT / Display the current value of X
ADD ONE / Increment X by 1
STORE X / Store the new value of X
LOAD Counter / Load the current counter value
ADD ONE / Increment the counter by 1
STORE Counter / Store the updated counter value
LOAD X / Load the value of X
SKIPCOND 000 / If AC<0 (X is less than 10), continue loop
JUMP ENDLOOP / If X is not less than 10, terminate loop
LOAD Counter / Load the final counter value
OUTPUT / Display the counter
ENDLOOP , HALT / Terminate the program
X, DEC 0 / Memory location for X (initialized to 0)
Counter, DEC 1 / Memory location for Counter (initialized to 1)
ONE, DEC 1 / Constant value 1
Example: if the entered value is 5, the values 5,6,7,8,9,10 (one number per line) will be displayed followed by the number of iterations. Note that the number 10 should be displayed.
I tried many things but the loop doesn't stop , it keep going after 10
ORG 400 / Start at adress 400
INPUT / Take a number from the user
STORE X / Store INPUT in memory location X
LOAD ONE / Load the constant value 1
STORE Counter / Store it in the Counter Memory location
LOOP, LOAD X / Load the value of X
OUTPUT / Display the current value of X
ADD ONE / Increment X by 1
STORE X / Store the new value of X
LOAD Counter / Load the current counter value
ADD ONE / Increment the counter by 1
STORE Counter / Store the updated counter value
LOAD X / Load the value of X
SKIPCOND 000 / If AC<0 (X is less than 10), continue loop
JUMP ENDLOOP / If X is not less than 10, terminate loop
LOAD Counter / Load the final counter value
OUTPUT / Display the counter
ENDLOOP , HALT / Terminate the program
X, DEC 0 / Memory location for X (initialized to 0)
Counter, DEC 1 / Memory location for Counter (initialized to 1)
ONE, DEC 1 / Constant value 1
Share
Improve this question
asked Nov 19, 2024 at 11:09
ZiwaseemiZZiwaseemiZ
1
2
|
1 Answer
Reset to default 0You are incrementing X by one (and another one, and another...) and then comparing it to zero.
So how can you compare it to 10?
You can define 10 (possibly 11) as a constant. Then subtract that constant from X and compare the result with zero. Experiment with less than 000
and greater than 800
tests.
本文标签:
版权声明:本文标题:assembly - Input a number from the user and store it in a memory location (X) , loop as long as long as the value is less then 1 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745565533a2663735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
LOOP
. Also10
is never mentioned in the code either. Anyway, use your simulator to single step the code and see where it goes wrong. – Jester Commented Nov 19, 2024 at 11:12