Square a number
This is basically the same as the last problem except that this time we want to keep track of which square we're up to.

As before, let's store the square number in S and the bit we add on in A - it will have to be increased by TWO each time.
The user's number can go in N and the counter in C.

  1. Input a number into N
  2. Load C with ONE
  3. Load S with ONE
  4. Load A with THREE
  5. If C and N are equal, output S and stop.
  6. Increment C
  7. Add A to S
  8. Increment A twice
  9. Go to step 5

 INP N
 LDA #1
 STA C
 STA S
 LDA #3
 STA A
LOOP: LDA C
 SUB N
 BEQ END
 INC C
 LDA S
 ADD A
 STA S
 INC A
 INC A
 JMP LOOP
END: OUT S
 HLT

INP N
LDA #1
STA C
STA S
LDA #3
STA A
LOOP: LDA C
SUB N
BEQ END
INC C
LDA S
ADD A
STA S
INC A
INC A
JMP LOOP
END: OUT S
HLT

Assembler