Loops/While: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1:
{{task|Iteration}}Start an integer value at 1024. Loop while it is greater than 0. Print the value (with a newline) and divide it by two each time through the loop.
 
=={{header|6502 Assembly}}==
Code is called as a subroutine (i.e. JSR LoopsWhile). Specific OS/hardware routines for printing are left unimplemented.
<lang 6502asm>LoopsWhile: PHA ;push accumulator onto stack
 
LDA #$00 ;the 6502 is an 8-bit processor
STA Ilow ;and so 1024 ($0400) must be stored in two memory locations
LDA #$04
STA Ihigh
WhileLoop: LDA Ilow
BNE NotZero
LDA Ihigh
BEQ EndLoop
NotZero: JSR PrintI ;routine not implemented
LSR Ihigh ;shift right
ROR Ilow ;rotate right
JMP WhileLoop
 
EndLoop: PLA ;restore accumulator from stack
RTS ;return from subroutine</lang>
=={{header|ActionScript}}==
<lang actionscript>var i:int = 1024;
Anonymous user