0
내가 벨로우즈가있는 밉스 코드에서 오버플로가 발생할 때 확인하는 좋은 루프는 무엇입니까? 그것은 기본적으로 예금을 계정에 추가함으로써 수표 책을 균형 잡기 위해 내놓은 프로그램입니다. 오버플로가 발생하면 잘못된 값이 계속 표시됩니다. 값이 받아 들여지는 경우 오버플로가 발생하고 잘못된 값을 수락하지 않고 다른 값을 묻는 루프가 필요합니다.감지 오버플로 추가
# Functional Description:
# This program can be used to balance your check book.
# <DESCRIBE OVERFLOW FEATURE HERE>
#####################################################################
# Pseudocode:
# Print Header;
# s0 = 0;
# loop: Prompt user for transaction;
# v0 << transaction amount;
# if (v0 = 0) done;
# s0 = s0 + v0;
# PSEUDOCODE FOR OVERFLOW DETECTION ALGORITHM HERE>
# cout << s0
# go to loop
# done:
# cout << "Adios Amigo"
#
######################################################################
# Register Usage:
# $v0: Transaction Amount
# $s0: Current Bank Balance
# <HERE YOU DECLARE ANY ADDITIONAL REGISTERS USED>
######################################################################
.data # Data declaration section
Head: .ascii "\n\tThis program, written by <YOUR NAME>,"
.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:"
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