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. I have attempted to do this within the loopRow
LOOP. 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. 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. You really want to compare just the character, so use CMP CL, 'C'
and CMP AL, 'C'
respectively.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.