Я работаю над программой, использующей собственные инструкции MIPS, которые позволят пользователю вводить три десятичных числа в виде строк с нулевым символом в конце.
Каждое число не может превышать шесть цифр.Если пользователь вводит запятую (например, 123 456), удалите запятую из памяти.
Первое число, сохраненное в адресе памяти 0x10000000, второе в 0x10000008 и третье в 0x10000010.
Мой коднеэффективно.Я это уже знаю, но мне проще, чем использовать подпрограммы, потому что я плохо понимаю MIPS.
Пожалуйста, предложите.
Код
.globl main
.globl main2
.globl main3
.globl firstNumCountChr
.globl firstIncremincrem
.globl secondNumCountChr
.globl secondNumIncrem
.globl thirdNumCountChr
.globl thirdNumInCrem
.data
.text
# 0x10000000 will store first number
# 0x10000008 will store second number
# 0x10000010 will store third number
main:
#Input first number
lui $a0, 0x1000
ori $a0, 0x0000 #reads number into memory(0x10000000)
addi $a1, $0, 8 #7 characters
addi $v0, $0, 8
syscall
#removing comma of first number
addi $t1, 0 #$t1 is the counter set to 0
add $t3, 0x2c # 0x2c is acsii of "," in hex
firstNumCountChr:
lb $t2, 0($a0) #load first byte from address in $a0
beq $t2, $0, end #if $t2 == 0 go to end
or $0, $0, $0 #NOP
bne $t2, $t3, firstNumIncrem #branch if symbol doesn't equal ","
or $0, $0, $0
add $t4, $a0, $0 #$t4 will save position of ","
firstNumIncrem:
addi $t0, $0, 1 #increment address
addi $t1, $t1, 1 #increment counter
j firstNumCountChr #loop
main2:
#inputing second number
lui $a0, 0x1000
ori $a0, 0x0008 #reads number into memory(0x10000008)
addi $a1,$0, 8 #7 characters
addi $v0, $0, 8
syscall
#removing comma of second number
addi $t1, 0 # $t1 is the counter set to 0
add $t3, 0x2c # 0x2c is acsii of "," in hex
secondNumCountChr:
lb $t2, 0($a0) # load first byte from address in $a0
beq $t2, $0, end # if $t2 == 0 go to end
or $0, $0, $0 # NOP
bne $t2, $t3, secondNumIncrem # branch if symbol doesn't equal ","
or $0, $0, $0 # NOP
add $t4, $a0, $0 # $t4 will save position of ","
secondNumIncrem:
addi $t0, $0, 1 #increment address
addi $t1, $t1, 1 #increment counter
j secondNumCountChr #loop
main3:
#inputting third number
lui $a0, 0x1000
ori $a0, 0x0010 #reads number into memory(0x10000010)
addi $a1, $0, 8 #7 characters
addi $v0,$0, 8
syscall
#removing comma of third number
addi $t1, 0 #$t1 is the counter set to 0
add $t3, 0x2c # 0x2c is acsii of "," in hex
thirdNumCountChr:
lb $t2, 0($a0) #load first byte from address in $a0
beq $t2, $0, end # if $t2 == 0 go to end
or $0, $0, $0
bne $t2, $t3, thirdNumIncrem #branch if symbol doesn't equal ","
or $0, $0, $0
add $t4, $a0, $0 # $t4 will save position of ","
thirdNumIncrem:
addi $t0, $0, 1 #increment address
addi $t1, $t1, 1 #increment counter
j thirdNumIncrem #loop
end:
add $0, $0, $0