Answer to Question #328446 in Assembler for Nov

Question #328446

a) Write an assembly program using MARIE's assembly Instruction set that prompts the user to enter a non-negative integer that is less than 10. The program should include a subroutine that keeps prompting until a valid value is obtained. When a valid number is entered, it will be displayed. (Hint: Use JNS & JUMPI instructions to implement the subroutine)

N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it (not a screenshot!). Example: Subt One /Subtract 1 from AC


1
Expert's answer
2022-04-13T14:21:04-0400
ORG    256        
start,     JnS     Display       / call Display, start running with instruction AFTER foo
 
     INPUT            / get value N
    STORE        N    / save N
    SUBT        N10        / N-10 (compare with 10)
    SKIPCOND    00        / if N < 10 then OK
    JUMP        start        / else go to back and try again

    LOAD        N        / restore N
    ADD  N0                / N to ASCII
    OUTPUT                / display N

    HALT

Display,    hex     256      / stores address to use when returning from Display
While,   load        AddrMsg   / CurAddr = &(msg[index])
         add         Index
         store       CurAddr
         clear                 / acc = msg[index]
         addi        CurAddr
         skipcond    800       / if msg[index] > null go ahead and print,
         jump        Done      / otherwise we're done
Print,   output
         load        Index     / index++
         add         Incr
         store       Index
         jump        While     / repeat loop for next char
Done,    JumpI   Display      / return from Display (to the address we stored when Display was called)

MsgSt,   dec         78        / 'N'
         dec         58       / ':'
 
Null,    dec         0         / '\0'
AddrMsg, hex         26E         / addr of MsgSt
Index,   dec         0         / current index into msg[]
CurAddr, hex         0         / addr of msg[index]
Incr,    dec         1         / for ++
N,       dec  0
N10,     dec  10
N0,       dec  48 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS