assembly 有人知道如何在汇编语言中添加数组和循环吗?如何修复错误?[关闭]

oyjwcjzk  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(94)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
6天前关闭
Improve this question

section .data
    station dd 0
    pressure dd 0
    choice db 0

    ; Strings for prompts and messages
    prompt_station db "Enter the station number: ", 0
    prompt_pressure db "Enter the gas pressure  : ", 0
    message_invalid db "Are you sure you entered the right pressure? Please check again.", 10, 0
    message_high db "Station %d with gas pressure %d Pascal is too high and dangerous. There is a gas leakage in this station.", 10, 0
    message_risk db "Station %d with gas pressure %d Pascal could be at risk of gas leakage. There might be gas leakage in this station.", 10, 0
    message_normal db "Station %d with gas pressure %d Pascal is normal. There is no gas leakage in this station.", 10, 0
    separator db "---------------------------------------------------------------------", 10, 0
    prompt_continue db "\nDo you want to continue? ", 0
    message_precautions db "- PRECAUTIONS FOR GAS LEAKAGE - ", 10, "1. Stop the gas flow at the container (shut off valves).", 10, "2. Turn off all naked flames and eliminate all sources of ignition.", 10, "3. Do not turn electrical switches ON or OFF.", 10, "4. If leak is indoors, open all windows and doors, to disperse the gas.", 10, "5. If the leak cannot be stopped or a significant leak has occurred, evacuate the premises.", 10, 0

section .text
    global _start

_start:
    ; Input station number
    mov eax, 4        ; sys_write
    mov ebx, 1        ; STDOUT
    mov ecx, prompt_station
    mov edx, prompt_station_len
    int 0x80

    mov eax, 3        ; sys_read
    mov ebx, 0        ; STDIN
    mov ecx, station
    mov edx, 4        ; Read up to 4 bytes (assuming integer input)
    int 0x80

    ; Input gas pressure (similar code as above for pressure input)

    ; Evaluate pressure and print messages (similar logic as C++)

    ; Print separator
    ; (Similar code as C++ to print separator)

    ; Prompt and read choice
    ; (Similar code as C++ for choice input)

    ; Check choice and continue or exit
    ; (Similar code as C++ for choice validation and continuation)

exit_program:
    ; Print precautions or exit message
    ; (Similar code as C++ to print precautions or exit message)

    ; Exit program
    mov eax, 1
    xor ebx, ebx
    int 0x80

section .data
    prompt_station_len equ $ - prompt_station
    ; Define lengths of other strings/messages here if necessary

我是新来的,我不知道如何修复错误

pxyaymoc

pxyaymoc1#

一个明显的错误是你计算 prompt_station_len 的方式。

section .data
 station dd 0
 pressure dd 0
 choice db 0

 ; Strings for prompts and messages
 prompt_station db "Enter the station number: ", 0
 prompt_pressure db "Enter the gas pressure  : ", 0
 ...
 message_invalid db "Are you sure you entered the right pressure? Please check again.", 10, 0
 message_high db "Station %d with gas pressure %d Pascal is too high and dangerous. There is a gas leakage in this station.", 10, 0
 message_risk db "Station %d with gas pressure %d Pascal could be at risk of gas leakage. There might be gas leakage in this station.", 10, 0
 message_normal db "Station %d with gas pressure %d Pascal is normal. There is no gas leakage in this station.", 10, 0
 separator db "---------------------------------------------------------------------", 10, 0
 prompt_continue db "\nDo you want to continue? ", 0
 message_precautions db "- PRECAUTIONS FOR GAS LEAKAGE - ", 10, "1. Stop the gas flow at the container (shut off valves).", 10, "2. Turn off all naked flames and eliminate all sources of ignition.", 10, "3. Do not turn electrical switches ON or OFF.", 10, "4. If leak is indoors, open all windows and doors, to disperse the gas.", 10, "5. If the leak cannot be stopped or a significant leak has occurred, evacuate the premises.", 10, 0
section .data
 prompt_station_len equ $ - prompt_station
 ; Define lengths of other strings/messages here if necessary

包含此equ的行必须紧跟在相关消息之后。$符号表示出现该符号的行的开始。并且该特定开始必须与消息的结尾一致:

prompt_station db "Enter the station number: ", 0
prompt_station_len equ $ - prompt_station

prompt_pressure db "Enter the gas pressure  : ", 0
prompt_pressure_len equ $ - prompt_pressure


因为 sys_write 是“长度驱动”的,所以不应该包含终止零:
删除零终止符:

prompt_station db "Enter the station number: "
prompt_station_len equ $ - prompt_station

prompt_pressure db "Enter the gas pressure  : "
prompt_pressure_len equ $ - prompt_pressure


或者减去1:

prompt_station db "Enter the station number: ", 0
prompt_station_len equ $ - prompt_station - 1

prompt_pressure db "Enter the gas pressure  : ", 0
prompt_pressure_len equ $ - prompt_pressure - 1


对不起,但是你对“添加数组和循环”的关注没有进一步的解释!

相关问题