We are supposed to swap the upper half with lower half, and my code does this but the problem is the last line is supposed to be the "C:>FILE_NAME". But the C in that line is on the second to the last. Also it is missing one line. I've been trying to play around with the numbers in CX but I'm not getting anywhere. Here is the code:
;Swap two halves of the screen crosswise
JMP START ;This will start the program
START:
MOV AX, 0B800H
MOV ES, AX ;Assign Video Display Area to ES
MOV DS, AX ;Assign Video Display Area to DS
MOV SI, 0
MOV DI, (80*2)*(12) ;Lower half of screen
MOV CX, 13 ;Loop for half of screen
OUTERLOOP:
PUSH CX
MOV CX, 80 ;COLUMNS. I GET IT NOW!
INNERLOOP:
MOV AL, [DS:SI]
MOV B[ES:DI], AL
ADD DI, 2
MOV BL, [ES:DI]
MOV B[ES:SI], BL
ADD SI, 2
LOOP INNERLOOP
POP CX
LOOP OUTERLOOP
INT 20H
Your inner loop does the swapping wrong. The first block copies a character from column
c
in the top half to the bottom half, then the second block copies the character from columnc+1
in the bottom to columnc
in the top. To swap, you should read the same column from both halves and write them back swapped. Such as:Also it's only copying a single byte, that is it doesn't copy the attribute (color). I don't know if that's intentional or not. You can change to 16 bit registers
AX
andBX
and then it will copy attributes as well.All the segment overrides are unnecessary and you only need to copy 12 lines, so set
CX
to 12.