Здравствуйте. В настоящее время я изучаю программирование на языке ассемблера MIPS. Я пытаюсь распечатать ответ, усеченный только до одного знака после запятой. Например, 127.0 вместо 127.000000, но он все еще печатает 127.000000 Спасибо за помощь.
Вот код:
.data
height: .asciiz "Height of right triangle: "
width: .asciiz "\nWidth of right triangle: "
result: .asciiz "\nArea of right triangle is "
height_input: .float 0.0
width_input: .float 0.0
result_input: .float 0.0
divide_by_2: .float 2.0
###########################################################
.text
main:
li $v0, 4 # print string syscall
la $a0, height # load the address of height
syscall
li $v0, 6 # read float syscall
syscall
s.s $f0, height_input # move input into the register for height
li $v0, 4 # print string syscall
la $a0, width # load the address of width
syscall
li $v0, 6 # read float syscall
syscall
s.s $f0, width_input # move input into the register for width
l.s $f0, height_input
l.s $f1, width_input
l.s $f4, divide_by_2
mul.s $f2, $f0, $f1 # multiply height times width
div.s $f3, $f2, $f4 # divide by 2 to get the area
# now we want to truncate to have only one decimal point
li $t5, 100
mtc1 $t5, $f5
cvt.s.w $f5, $f5
mul.s $f3, $f3, $f5
trunc.w.s $f3, $f3
cvt.s.w $f3, $f3
div.s $f3, $f3, $f5
s.s $f3, result_input
li $v0, 4 # print string syscall
la $a0, result # load address of result
syscall
li $v0, 2 # print float syscall
l.s $f12, result_input # move the area into the f12 register to print
syscall
j exit # jump to the exit subroutine to end the program
exit:
li $v0, 10 # exit program
syscall
###########################################################