LOOP REGISTER BC and EXIT to LOOP in ASSEMBLY

By gasparrini

Champion (301)

Аватар пользователя gasparrini

17-07-2016, 12:42

Hello,

I would have a little trouble to make a loop with
BC register 16-bit, but as I built the program
It does not work well, because the LOOP goes to infinity and not out
from LOOP to return to BASIC.

Can you help me with the code to make it work ??

below there is the assembly source that should
fix it to make it work well.

	.org $D000 - 7

	.db $fe
	.dw startProgram,endProgram,startProgram

startProgram:

LDIRVM        .equ $005C ; routine of BIOS used to fill the VRAM
PRINTCHAR  .equ $1880 ; character display address VPOKE6272,CHAR

 LD H,0   ; X 
 LD L,3  ; Y
 CALL $C6 ; CALL LOCATE X,Y ROUTINE BIOS
 LD BC,576 ; Counter of 576 characters

LOOP:
 ld A,156 ; WALL BACKGROUND
 CALL $A2 ; PRINT CHR$(156)
 DEC BC   ; Decrements 1 byte of the 16 bit register BC
 OR C
 JR NZ,LOOP ; if not is Z=1 then goto LOOP
 RET        ; RETURN TO BASIC

endProgram:

.end

This little assembly source is suitable for SCREEN 1.

I look forward to your positive response
Thanks in advance
Best Regards
AG

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By jltursan

Prophet (2193)

Аватар пользователя jltursan

17-07-2016, 13:14

You're missing LD A,B:

LOOP:
 ld A,156 ; WALL BACKGROUND
 CALL $A2 ; PRINT CHR$(156)
 DEC BC   ; Decrements 1 byte of the 16 bit register BC
 LD A,B ; <<<<<<< YOU MISSED THIS
 OR C
 JR NZ,LOOP ; if not is Z=1 then goto LOOP
 RET        ; RETURN TO BASIC