Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Unsigned additiong overflow (http://www.go4expert.com/forums/unsigned-additiong-overflow-t6189/)

eclipse 4Sep2007 02:40

Unsigned additiong overflow
 
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



All times are GMT +5.5. The time now is 14:26.