Shift list elements to left by 3: Difference between revisions

m (syntax highlighting fixup automation)
Line 1,598:
<pre>
4, 5, 6, 7, 8, 9, 1, 2, 3
</pre>
 
=={{header|Z80 Assembly}}==
===Zilog Z80===
This example code will not work on the Game Boy, as the Game Boy does not have the <code>RLD</code> or </code>RRD</code> instructions.
<syntaxhighlight lang="z80">PrintChar equ &BB5A ;address of Amstrad CPC firmware routine, writes accumulator to stdout.
 
org &1000
ld hl,myarray_end-1 ;HL must point to the last byte in the array.
ld b,9 ;byte count
call RLCA_RANGE
 
ld hl,myarray_end-1
ld b,9
call RLCA_RANGE
 
ld hl,myarray_end-1
ld b,9
call RLCA_RANGE
 
ld hl,myarray
jp PrintString
;ret
 
myarray:
;pre-convert these numbers to ascii so that the job is easier.
byte &31,&32,&33,&34,&35,&36,&37,&38,&39
myarray_end:
byte 0 ;null terminator
 
RLCA_RANGE: ;DOESN'T WORK ON GAME BOY
;rotates a range of memory, e.g. &1000 = &23,&45,&67,&89 > &45,&67,&89,&23
;point HL at the end of the memory range this time.
ld a,(hl)
push hl
push bc
loop_RLCA_RANGE_FIRST:
RLD
DEC HL
djnz loop_RLCA_RANGE_FIRST
pop bc
pop hl
push hl
push bc
loop_RLCA_RANGE_SECOND:
RLD
DEC HL
djnz loop_RLCA_RANGE_SECOND
pop bc
pop hl
RLD
ret
 
PrintString:
ld a,(hl)
or a
ret z
call PrintChar
inc hl
jr PrintString</syntaxhighlight>
 
{{out}}
<pre>
456789123
</pre>
1,489

edits