【问题标题】:Syntax errors in my assembly code [closed]我的汇编代码中的语法错误[关闭]
【发布时间】:2011-11-23 08:15:40
【问题描述】:

我有这个代码,我想知道是否有人愿意帮助我让它工作。

TITLE MASM Template                     (main.asm)

; Description: this code is supposed to print out each letter followed by a space and then the capitalized version on seperate lines
; Revision date:

INCLUDE Irvine32.inc
.data

myArray byte 'l','s','d','t','h','c','f','u','c','k'    ;my array of 10 characters
.code
main PROC

    mov ecx,0                                        ;clears ecx
    mov ecx,LENGTHOF myArray                         ;should be 10
    mov edi,OFFSET myArray                   ;will point to the beginning of the array
    mov eax,0                                       ;clears eax
    mov esi,0                                       ;clears esi

LOne:

    mov eax,myArray[esi]          ;points the pointer at the beginning of myArray
    WriteChar eax                     ;prints the designated value in the array
    WriteChar 32                    ;prints a space (32 is the ascii value for ' ')
    sub eax,32                      ;subtracts 32 from the ascii value of the char
                         ;the capital version of each letter is -32 of its ascii value
    WriteChar eax           ;prints the capital version
    call CLRF               ;prints new line
    inc esi                 ;increments esi to the next array value
    dec ecx                 ;decrements ecx, moving it through the array

    loop LOne               ;loops back until ecx is equal to zero

    exit
main ENDP

END main

它不会编译给我语法错误。

1>main.asm(22):错误 A2008:语法错误:eax
1>main.asm(23):错误 A2008:语法错误:WriteChar
1>main.asm(26): 错误 A2008: 语法错误: eax
1>main.asm(21): 错误 A2022: 指令操作数必须相同大小
1>main.asm(27):错误 A2006:未定义符号:CLRF

【问题讨论】:

  • 好吧,不管代码是做什么的,在一篇 SO 帖子中同时看到 LSD、THC 和 F*CK 对我来说是第一次!
  • 发生了什么,它与您想要/期望的有什么不同?我没有看到您正在打印换行符的任何地方,cmets 似乎表明您可能想要,但这是唯一立即跳出的问题。
  • 代码无法编译它在第 22、23、24、26 行显示语法错误
  • 哦,是的,我遗漏了新行代码,调用 CLRF 工作正常吗?不是说修复了代码,而是谢谢
  • 什么不能正常工作?请提出简洁的问题。

标签: assembly syntax masm irvine32


【解决方案1】:

啊,Kip Irvine 的书……我记得我想写自己的图书馆,这样我就不必使用他的书了……

你需要call那些库函数,这不是你在汇编语言中的做法。

假设他的库自第 4 版以来没有改变,WriteChar 要求您将要写入的字符移动到寄存器 alCrlf 不需要任何参数,因此您可以直接调用它,但拼写很重要。 ;)

mov     al, BYTE PTR [edi + esi]
call    WriteChar                  ; print the character found at [edi + esi]

call    Crlf                       ; print a new line

语法正确后,您需要仔细检查您的逻辑。

【讨论】:

  • 现在唯一阻止它编译的是在“writeChar”行中缺少运算符我导入了 irvine 库所以它们应该可以工作,为什么它说缺少运算符?这意味着什么
  • 是的,很多人都告诉我关于 kip irvine 的坏事,这让我感到非常不便,因为这是我的老师用来上课的材料。他甚至使用了 kip 的幻灯片!所以显然我对这种语言的全部理解来自这个人以及我能找到的少量互联网资源......
  • 如果您想要其他资源,请查看The MASM Forum
猜你喜欢
  • 1970-01-01
  • 2016-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多