Unsigned additiong overflow

Discussion in 'Assembly Language Programming (ALP) Forum' started by eclipse, Sep 3, 2007.

  1. eclipse

    eclipse New Member

    Joined:
    Sep 3, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I need some help on completing my little project I'm doing to enhance my skills a little bit. My program is to read in an amount transaction and add the amounts together. If the amount added together exceeds the nth bit, then an overflow occurs. Below is my code for what I've done so far:

    Code:
    #####################################
    
    	.data			# Data declaration section
    
    Head: 	.ascii	"\n\tThis program"
    
    	.ascii	" can be used to balance your check book."
    
    	.asciiz	"\n\n\t\t\t\t\t\t\t\t\t  Balance"
    
    tabs:	.asciiz	"\t\t\t\t\t\t\t\t\t"
    
    tran:	.asciiz	"\nTransaction:"
    
    error:	.asciiz	"Overflow Occurred – Last Transaction Ignored"	#### Overflow message
    
    bye:	.asciiz	"\n  ****  Adios Amigo  **** "
    
    
    
    	.text			# Executable code follows
    
    main:
    
    	li	$v0, 4		# system call code for print_string
    
    	la	$a0, Head		# load address of Header message into $a0
    
    	syscall			# print the Header
    
    
    
    	move	$s0, $zero		# Set Bank Balance to zero
    
    loop:
    
    	li	$v0, 4		# system call code for print_string
    
    	la	$a0, tran		# load address of prompt into $a0
    
    	syscall			# print the prompt message
    
    
    
    	li	$v0, 5		# system call code for read_integer
    
    	syscall			# reads the amount of  Transaction into $v0
    
    
    
    	beqz	$v0, done		# If $v0 equals zero, branch to done
    
    	addu $s0, $s0, $v0	# add transaction amount to the Balance
    
    
    
    	li	$v0, 4		# system call code for print_string
    
    	la	$a0, tabs		# load address of tabs into $a0
    
    	syscall			# used to space over to the Balance column
    
    	
    
    	li	$v0, 1		# system call code for print_integer
    
    	move	$a0, $s0		# move Bank Balance value to $a0 
    
    	syscall			# print Bank Balance
    
    	b 	loop		# branch to loop
    
    
    
    done:	li	$v0, 4		# system call code for print_string
    
    	la	$a0, bye		# load address of msg. into $a0
    
    	syscall			# print the string
    
    
    
    	li	$v0, 10		# terminate program run and
    
    	syscall			# return control to system
    
    
    
    				# END OF PROGRAM
     
    Last edited by a moderator: Sep 4, 2007

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice