This code below successfully moves a given string into a register, in this case, register 1; using r2 as a counter. However, r2 has to be hardcoded with the length of the string for the loop to finalize correctly. Is it possible to implement a similar solution without hardcoding a counter?
ORG 100H
MOV R2, #13D
MOV R1, #0
MOV DPTR,#DAT0
AGAIN: MOV A, R1
MOVC A, @ A+DPTR
MOV P1, A
INC R1
DJNZ R2, AGAIN
SJMP $
DAT0: DB "(C) XYZ Inc.",0
END
If you don't want to send the terminating zero byte to P1, then jump out of the loop with the
JZinstruction that jumps if the accumulatorAcontains zero:If you do want to send the terminating zero byte to P1, then only loop back if the last byte send was non-zero. Use the
JNZinstruction that jumps if the accumulatorAcontains anything but zero: