“期望表达”第1行出现错误。如何解决? [英] "Expression Expected" error on line 1. How to fix it?

查看:112
本文介绍了“期望表达”第1行出现错误。如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到第1行,期望表达错误,我不确定为什么。

I am getting the "In line 1, expression expected" error and I am not sure why.

我正在使用nand2tetris的CPU仿真器。我尝试将第1行更改为5,但并不能解决问题。首先,我只是不明白问题是什么。

I am using the CPU Emulator from nand2tetris. I tried changing line 1 to 5, but it did not solve the problem. I just do not get what is the problem in the first place.

@j
D=5;
@i;
M=1;
@5
@i
D=M
D=D-A;
@END
D;JGT
@j
@1
M=M-A
@i
@1
M=M+A
@LOOP
0;JMP

我要做什么重新创建就是这个循环:
J = 5
for(i = 1; i< 5; i ++){
j--
}

What I am trying to recreate is this loop: J=5 for(i=1; i<5; i++) { j-- }

推荐答案

乍看之下有几个问题。

首先,D = 5不是有效的Hack操作。如果要将5加载到D中,则必须先将其加载到A中,然后再移动到D:

First, D=5 is not a valid Hack operation. If you want to load 5 into D, you have to first load it into A and then move to D:

@5
D=A

是跳转定界符,后跟一个跳转条件(例如,JEQ或无条件跳转的JMP)。您有几行(包括第1行),其中有一个;但没有跳跃条件。

Second, ; is the jump delimiter, and should be followed by a jump condition (such as JEQ, or JMP for an unconditional jump). You have several lines (including line 1) where you have a ; but no jump condition. These should be removed.

最后,您可能应该阅读有关Hack汇编语言语法的书页,以确保您清楚其工作方式。特别是,在上面的代码中,您尚未指定END和LOOP之类的跳转目标。这是通过(LABEL)构造完成的。

Finally, you should probably review the book pages on the Hack assembly language syntax to make sure you are clear on how it works. In particular, in the above code, you haven't specified your jump targets like END and LOOP. This is done with the (LABEL) construct.

这篇关于“期望表达”第1行出现错误。如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆