MIPS: Printing Out a Histogram -


i'm writing mips program (assembly language) takes in 10 integers , prints out histogram represented asterisks.

e.g.:

user input of 1, 2, 3, 4

output:

* ** *** **** 

i have of code written in mips. problem running printing out correct length of asterisks. of printing out histogram of same length; first user inputed integer.

# program functionality: 

.data

menu:   .asciiz     "\n1. new histogram\n2. print histogram\n3. quit\n" prompt: .asciiz     "\nenter 10 numbers between 0 , 50 (inclusive):\n" prompt1: .asciiz    "\nenter valid number:\n" asterisk: .asciiz   "*" space: .asciiz      "\n" array:  .word       0:10 

.text main:

do:      jal print_menu     li  $v0, 5     syscall      beq $v0, 1, new     beq $v0, 2, print     beq $v0, 3, quit j    # end      new:         jal new_user         j       print:         jal print_user         j    j   quit  print_menu:      la  $a0, menu     li  $v0, 4     syscall     jr  $ra   new_user:     la  $a0, prompt     li  $v0, 4     syscall       enter_loop:          la  $t0, array         li  $t1, 10          enter_loop_2:              la  $a0, prompt1             li  $v0, 4             syscall              li  $v0, 5             syscall              sw  $v0, ($t0)              addi    $t1, $t1, -1             beqz    $t1, end_loop_2              addi    $t0, $t0, 4             j   enter_loop_2               end_loop_2:             jr  $ra   print_user:     la  $t0, array     li  $t1, 10      ploop:      la  $a0, space     li  $v0, 4     syscall           asterisk_fun:               li  $v0, 1             lw  $a0, ($t0)             syscall               counter:                  la  $a0, asterisk                 li  $v0, 4                 syscall                  addi    $a0, $a0, -1                 beqz    $a0, asterisk_end                  j   counter              asterisk_end:                  jr  $ra            addi    $t1, $t1, -1         beqz    $t1, endploop          addi    $t0, $t0, 4          j   ploop           endploop:         jr  $ra    quit:     li  $v0, 10     syscall 

the problems overwriting register $a0 in counter address of asterisk, , used $a0 count number of items in bucket. easy solution use other register (e.g. $a1) count number of items:

that be:

     #... code     asterisk_fun:         li  $v0, 1         lw  $a1, ($t0)   # load number in $a1         move $a0, $a1    # move $a0 print         syscall             la  $a0, asterisk         counter:              li  $v0, 4             syscall              addi    $a1, $a1, -1          # use $a1 keep counter             beqz    $a1, asterisk_end              j   counter          asterisk_end:      # ... more of code 

Comments

  1. Mips: Printing Out A Histogram - >>>>> Download Now

    >>>>> Download Full

    Mips: Printing Out A Histogram - >>>>> Download LINK

    >>>>> Download Now

    Mips: Printing Out A Histogram - >>>>> Download Full

    >>>>> Download LINK g8

    ReplyDelete

Post a Comment

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -