[英]Assembly Language “CMP”
I am working on my first project for my Machine Organization class. 我正在为我的机器组织课程从事第一个项目。 The program flips the screen from left to right.
该程序从左向右翻转屏幕。 This works fine and I have no issues with this.
这工作正常,我对此没有任何问题。 However, in addition to flipping the screen, my professor has also asked us to display all uppercase C's in red on grey.
但是,除了翻转屏幕之外,我的教授还要求我们将所有大写的C显示为灰色的红色。 I have attempted to do this within the
loopRow
LOOP. 我试图在
loopRow
LOOP中执行此loopRow
。 There are no errors when assembling, however, it does not work. 组装时没有错误,但是不起作用。 I have also tried comparing to the ASCII code value but this did not work either.
我也尝试过与ASCII码值进行比较,但这也不起作用。 Any suggestions?
有什么建议么?
MyCode SEGMENT
ASSUME CS:MyCode, DS:MyData
MainProg PROC
MOV AX, MyData
MOV DS, AX
MOV AX, 0B800h
MOV ES, AX
MOV BX, (25 * 160)
loop25:
SUB BX, 160
CALL flipRow
CMP BX, 0
JNE loop25 ;if not equal to 0, numLoops - 1 and repeat
MOV AH, 4Ch
INT 21h
MainProg ENDP
flipRow PROC
MOV DI, BX
ADD DI, 158
MOV SI, BX
loopRow:
MOV AX, ES: [DI]
MOV CX, ES: [SI]
MOV ES: [DI], CX
CMP CX, 'C' ;compare CX to 'C'
JNE next ;if != C go to next
MOV ES: [DI + 1], BYTE PTR 01111100b
next:
MOV ES: [SI], AX
CMP AX, 'C' ;compare AC to 'C'
JNE next2 ;if != C go to next2
MOV ES: [SI + 1], BYTE PTR 01111100b
next2:
DEC DI
DEC DI
INC SI
INC SI
CMP SI, DI
JL loopRow
RET
flipRow ENDP
MyCode ENDS
The usual advice applies: learn to use a debugger. 通常的建议适用:学习使用调试器。
That said, your problem is that you are comparing CX
and AX
, which contain the character and the attribute as well. 就是说,您的问题是您正在比较
CX
和AX
,它们也包含字符和属性。 You really want to compare just the character, so use CMP CL, 'C'
and CMP AL, 'C'
respectively. 您确实只想比较字符,所以分别使用
CMP CL, 'C'
和CMP AL, 'C'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.