Question

Write an example of an assembly language comment using MARS.

Write an example of an assembly language comment using MARS.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#this program is to store 2 numbers sum in assembly language

.data
A:          .word       # store first integer A
B:          .word       #storing 2nd Integer B
S:          .word       #this s integer is used to store A and B
Prompt1:    .asciiz "Input A: "
Prompt2:    .asciiz "input B: "
Result:     .asciiz "A+B = "

.text
main:
    #Prompt for integers A
    li $v0, 4          # Load instruction for printing the string
    la $a0, Prompt1    # Load Prompt1 into $a0
    syscall

    #Read first integer
    li $v0, 5      # Read first integer A
    la $t0, A    
    syscall

    #Store first integer A into the memory
    move    $t0, $v0  
    sw $t0, A     
  

    ##Prompt for integers B
    li $v0, 4          # Load instruction for printing the string
    la $a0, Prompt2    # Load prompt2 into $a0
    syscall

    #Read second integer
    li $v0, 5      # Read second integer
    la $t1, B      # $t0 = A
    syscall

    #Store second integer into memory
    move    $t1, $v0    # Move contents in $v0 to $t0
    sw $t1, B      # A = value at $t0
  

    #Add the two variables A and B and store it in S
    la $t2, S      # $t2 = S
    add     $t2, $t0, $t1   # $t2 = $t0 + $t1
    sw $t2, S      # S = value at $t2

    #Display the Result prompt
    la $a0, Result # Loads Output label to be printed
    li $v0, 4      # Sysycall to print string
    syscall

    #Display the sum
    lw $a0, S      # $a0 = value at S
    li $v0, 1      # Syscall to print integer
    syscall

    #exit out of the program
    li $v0, 10     # Loading exit code to $v0
    syscall

Add a comment
Know the answer?
Add Answer to:
Write an example of an assembly language comment using MARS.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT