-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquare a number.asm
36 lines (35 loc) · 1.05 KB
/
Square a number.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Square a number
#
#This is a program that squares a number by
#using one input command to allow the the
#user to input one number
#The square of the number input is shown in the output
#once the user inputs the number
#
#This version uses labels
#
#Label Address Use
#loop 03 Branch here...
#a 14 The number to square stored here
#b 15 The same number stored here
#constant 16 DAT one-stays the same
#square 17 DAT Square of the number is stored here
#end 11 Load square of number, output and end
IN #input a number
STO a #store it in both a and b
STO b
loop LDA b #loop - load b onto the accummulator
BRZ end #finally branch if it is zero to end
SUB constant #subtract one and store it in b
STO b
LDA square
ADD a
STO square
BR loop
end LDA square
OUT
COB
a DAT 000
b DAT 000
constant DAT 001
square DAT 000