Question

I want to write two programs using the MIPS assembly language of at least 5 lines

I want to write two programs using the MIPS assembly language of at least 5 lines

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

Program to print hello world

# "Hello World" in MIPS assembly # From: http://labs.cs.upt.ro/labs/so2/html/resources/nachos-doc/mipsf.html                 # All program code is placed after the  # .text assembler directive     .text   # Declare main as a global function     .globl  main     # The label 'main' represents the starting point main:         # Run the print_string syscall which has code 4         li      $v0,4           # Code for syscall: print_string        la      $a0, msg        # Pointer to string (load the address of msg)   syscall         li      $v0,10          # Code for syscall: exit        syscall         # All memory structures are placed after the    # .data assembler directive     .data   # The .asciiz assembler directive creates       # an ASCII string in memory terminated by       # the null character. Note that strings are     # surrounded by double-quotes msg:      .asciiz "Hello World!\n"

Program for loop

# Simple routine to demo a loop # Compute the sum of N integers: 1 + 2 + 3 + ... + N # From: http://labs.cs.upt.ro/labs/so2/html/resources/nachos-doc/mipsf.html         .text   .globl  main main:      # Print msg1    li      $v0,4           # print_string syscall code = 4         la      $a0, msg1               syscall         # Get N from user and save      li      $v0,5           # read_int syscall code = 5     syscall         move    $t0,$v0         # syscall results returned in $v0       # Initialize registers  li      $t1, 0          # initialize counter (i)        li      $t2, 0          # initialize sum        # Main loop body loop:  addi    $t1, $t1, 1     # i = i + 1     add     $t2, $t2, $t1   # sum = sum + i         beq     $t0, $t1, exit  # if i = N, continue    j       loop    # Exit routine - print msg2 exit:       li      $v0, 4          # print_string syscall code = 4         la      $a0, msg2       syscall         # Print sum     li      $v0,1           # print_string syscall code = 4         move    $a0, $t2        syscall         # Print newline         li      $v0,4           # print_string syscall code = 4         la      $a0, lf         syscall         li      $v0,10          # exit  syscall         # Start .data segment (data!)   .data msg1:     .asciiz "Number of integers (N)? " msg2:        .asciiz "Sum = " lf: .asciiz    "\n"
Add a comment
Know the answer?
Add Answer to:
I want to write two programs using the MIPS assembly language of at least 5 lines
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