将华氏温度值转换为摄氏温度的汇编语言程序。要实现的公式是 = ( − 32) × 5⁄9。所需的数据段:
- F_temp(字)
- C_temp(字)
- 值 32(字节)
- 值 5(字节)
- 值 9(字节)
- 提示输入(字符串)
- 输出消息(字符串)
堆栈用于将华氏值传递给子程序,并将计算出的摄氏值返回给主程序。为此将实施动态堆栈分配。华氏温度和计算出的摄氏温度值都将存储在数据段中定义的分配内存位置中。
到目前为止,我所拥有的是这段代码。当我运行程序时它说
Assemble: operation completed successfully.
它应该要求用户输入华氏温度。但它没有这样做。此外,在用户输入数字后,它应该将其转换为摄氏度并显示结果。
.data
F_temp: .word 0
C_temp: .word 0
Number1: .byte 32
number2: .byte 5
number3: .byte 9
enterNumber: .ascii "\nEnter a temperature in Fahrenheit: \n"
celsiusDegree: .ascii "\nCelsius temperature is: "
array: .word 0:25
welcome1: .ascii " \n This program converts Fahrenheit to Celsius \n\n"
.text
main:
la a0, welcome1 #display welcome message
li x0, 4
ecall
la x10,enterNumber #Ask user to write a number
li x17,4
ecall
la x6,array #store numbers array
li x30,25 #maximum of 25 integers are allowed to be entered
# F is in x10 #(F-32) * 5 / 9
addi x1, x0, 9 #t1 = 9
addi x2, x2, 5 #t0 = 5
addi s0, s0, 32 #s0 = 32
sub x10, x6, s0 #F-32
mul x10, x6, s0
div t0, t1, s0
done:
la x10,celsiusDegree #display celcius degree
ecall
exit:
ori a7, zero, 10 # define program exit system call
ecall # exit program