【发布时间】:2020-11-01 01:31:29
【问题描述】:
将华氏温度值转换为摄氏温度的汇编语言程序。要执行的公式是??? = (???? − 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
【问题讨论】:
-
文本“它不工作” - 应该替换为它正在在做什么。所有好的问题都有(1)展示问题的最小可能代码; (2) 它应该做什么; (3) 它做什么做什么。
-
@paxdiablo (1) 当我运行代码时,它并没有说有任何错误。 (2) 它应该要求用户输入一个数字,然后将该数字转换为摄氏度并显示结果。 (3) 它什么也没做,它没有像它应该的那样要求输入
标签: assembly riscv rars-simulator