Hailstone key - # # # # # This program computes the length...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
# This program computes the length of the hailstone series for some # starting number N. # # Peter Jensen # September 12, 2009 .data Prompt: .ascii "This program computes the length of the hailstone series for some starting number N.\n" .asciiz "Enter a positive integer N: " InputError: .asciiz "Invalid input - N must be positive" Space: .asciiz " " OverflowText: .asciiz "\nOverflow at step# " Output1: .asciiz "\nThe hailstone series starting from " Output2: .asciiz " converges in " Output3: .asciiz " step(s)." .text Main: # Display the initial prompt. li $v0, 4 la $a0, Prompt syscall # Input the integer. li $v0, 5 syscall # Integer returned in $v0 move $s6, $v0 # Keep original N in $s6 # If non-negative, print error and exit. beq $v0, $zero, BadInput bgez $v0, InputOK BadInput: li $v0, 4 la $a0, InputError syscall li $v0, 10
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
syscall # Program terminates InputOK: # Iteration code - compute the sequence. move $s0, $s6
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Hailstone key - # # # # # This program computes the length...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online