0
그래서 내 코드에서 어딘가에 잘못 갔다 고 생각하지만 사용자가 프로그램에 입력 한 정수를 16 진수로 변환하려고합니다. 내 첫 번째 문제는 입력 한 정수를 인쇄하는 프로그램을 얻을 수 없다는 것입니다. 오히려 그것은 정수의 주소를 인쇄하는 것처럼 보입니다. 나는 누군가가 올바른 방향으로 날 지점 수있는 기대했다MIPS 인쇄 오류
.data # Data declaration
# A+B -(C-D x E)
string1: .asciiz "Please enter an integer from range 0 to 32768: "
string2: .asciiz "Next integer: "
string3: .asciiz "Invalid input. Start over: "
string4: .asciiz "The hexadecimal value of the decimal integer "
string5: .asciiz "is: "
newline: .asciiz "\n"
.align 2
userinput: .space 100
var6: .asciiz "The result of A+B -(C-D x E) is: "
.text
main:
la $a0, string1 #load string one and print
li $v0, 4
syscall
li $s0, 1
la $a1, userinput
li $t1, 5 #set temporary variable to 5
li $t0, 0 #start of counter
input:
beq $t0, $t1, exit
li $v0, 5 # read integer
syscall
blt $v0, $zero, invalid # if input is less than zero
bgt $v0, 32768, invalid # if input is greater than 32768
beq $t0, 0, case1
beq $t0, 1, case2
beq $t0, 2, case3
beq $t0, 3, case4
beq $t0, 4, case5
case1:
sw $v0, 0($a1)
addi $t0, 1
la $a0, string2
li $v0, 4
syscall
j input
case2:
sw $v0, 4($a1)
addi $t0, 1
la $a0, string2
li $v0, 4
syscall
j input
case3:
sw $v0, 8($a1)
addi $t0, 1
la $a0, string2
li $v0, 4
syscall
j input
case4:
sw $v0, 12($a1)
addi $t0, 1
la $a0, string2
li $v0, 4
syscall
j input
case5:
sw $v0, 16($a1)
addi $t0, 1
la $a0, string2
li $v0, 4
syscall
j input
invalid:
la $a0, string3 #load string one and print
li $v0, 4
syscall
j input
exit:
la $t3, userinput # stores base address of user input array into $t3
li $t1, 1
li $t0, 0
la $a0, string4 # load string4
li $v0, 4 # print
syscall
move $a0, $t3 # move first number into a0
li $v0, 1 # print
syscall
la $a0, string5
li $v0, 4
syscall
jal convert
li $t1, 1
jal hexconvert
addi $s0, $s0, 1
slti $t7, $s0, 6
bne $t2, $zero, exit
j close
convert:
andi $t4, $t3, 15
sll $s4, $s4, 8
slti $t5, $t4, 10
bne $t5, $zero, else
addi $t4, $t4, 65
jal next
else:
addi $t4, $t4, 48
next:
add $s4, $s4, $t3
srl $t3, $t3, 4
addi $t1, $t1, 1
slti $t5, $t1, 5
bne $t5, $zero, convert
jr $ra
hexconvert:
andi $t4, $s4, 255
move $a0, $t4
li $v0, 11
syscall
srl $s4, $s4, 8
addi $s3, $s3, 1
slti $t1, $s3, 5
bne $t2, $zero, hexconvert
la $a0, newline
li $v0, 4
syscall
jr $ra
close:
li $v0, 10 # exit instruction
syscall
: 다음은 코드입니다. 나는 여전히 MIPS를 처음 접했습니다. 감사합니다.