简体   繁体   English

Nasm“指令预期”问题是我的编译器还是我的代码

[英]Nasm "instruction expected" problem is it my compiler or my code

I am fairly new to NASM and I already want to blow my brains out because I dont know why I keep getting this error "instruction expected" Line 14. Is it my compiler or my code.我对 NASM 还很陌生,我已经想大吃一惊了,因为我不知道为什么我一直收到这个错误“预期的指令”第 14 行。是我的编译器还是我的代码。 Please help me Ive been at this for hours and I don't know what to do at this point.请帮助我,我已经在这几个小时了,我现在不知道该怎么做。

section .data
  CELC DB ?
FARH DB ?
MSG1 DB 'INPUT VALUE OF CENTIGRADE','$'
MSG DB 'EQUIVALENT FARHRENEHEIT IS','$'

section .text
    global _start
section .code

_start:
    ASSUME CS:CSEG, DS:DSEG
       MOV AX,DSEG
       MOV DS,AX ; INITIALIZE DATA SEGMENT
       LEA DX,MSG1
       MOV AH, 01H
      
       INT 21H ; DISPLAY "INPUT VALUE IN CELC"
       MOV AH, 01H
      
       INT 21H ; INPUT VALUE IN CELC
       MOV CELC,AL ; MOVE THE INPUT VALUE TO 'CELC'
       MOV AL,CELC
       MOV CL,09H
       MOV CH,00H
       MUL CL ; AX=9*CELC
       MOV CL,05H

       DIV CL ; AL=AX/CL=(9*CELC)/5
       ADD AL,20H ; ADD 20H=32 TO AL TO GET FAHR
       MOV FARH, AL ; FAHR=(9*CELC)/5+32
       MOV AH,4CH
       INT 21H

Errors discovered in your code are almost never compiler bugs.在您的代码中发现的错误几乎从来都不是编译器错误。 Line 14 says ASSUME CS:CSEG, DS:DSEG which is MASM way to tell assembler which segment registers it should use for addressing segments CSEG and DSEG .第 14 行说ASSUME CS:CSEG, DS:DSEG这是 MASM 告诉汇编程序应该使用哪些段寄存器来寻址段CSEGDSEG的方式。 But instead of those segments (alias sections ) you declared .data , .text and .code .但是您声明的不是那些段(别名部分.data.text.code Beside that, NASM doesn't ASSUME .除此之外, NASM 不 ASSUME Comment out Line 14 and declare sections DATA and CODE , as is usual in DOS programs.注释掉第 14 行并声明DATACODE部分,这在 DOS 程序中很常见。

NASM requires references to the contents of memory variables be in square brackets. NASM 要求对 memory 变量内容的引用放在方括号中。 Instead of代替
MOV CELC,AL; MOVE THE INPUT VALUE TO 'CELC' MOV CELC,AL; MOVE THE INPUT VALUE TO 'CELC' you need MOV [CELC],AL etc. Or employ unused registers BX,SI,DI instead of memory variables. MOV CELC,AL; MOVE THE INPUT VALUE TO 'CELC' ,您需要MOV [CELC],AL等。或者使用未使用的寄存器 BX、SI、DI 代替 memory 变量。 BTW its better to calculate temperatures as 16bit signed integers, otherwise you are restricted to the range 0..255 degrees.顺便说一句,最好将温度计算为 16 位有符号整数,否则您将被限制在 0..255 度的范围内。

Also revise DOS function and concentrate to the proper function identificator in AH before INT 21h .还要在INT 21h之前修改DOS function并在AH中集中到正确的 function 标识符。 You'll need AH=09h to display the prompt.您需要AH=09h来显示提示。 Don't forget that when the user enters 5 on the keyboard, DOS function AH=1 returns 35h in AL , which is not the value you should calculate with.不要忘记,当用户在键盘上输入5时,DOS function AH=1AL中返回 35h,这不是您应该计算的值。

I recommend to start with some HelloWorld example, learn to use TLINK and TurboDebugger in DOSBox and only when all works, add more functionality, step by step.我建议从一些 HelloWorld 示例开始,学习在 DOSBox 中使用 TLINK 和 TurboDebugger,并且只有在一切正常的情况下,逐步添加更多功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM