-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLab8Reference.asm
More file actions
72 lines (64 loc) · 1.37 KB
/
Lab8Reference.asm
File metadata and controls
72 lines (64 loc) · 1.37 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
; Starting code with basic constants and simple subroutine
ORG 0
Start:
IN Quad
CALL Mod6
CALL DisplayWithNeg
JUMP Start
;******************************************************************************
; Abs: 2's complement absolute value
; Returns abs(AC) in AC
; Negate: 2's complement negation
; Returns -AC in AC
;******************************************************************************
Abs:
JPOS Abs_r ; If already positive, return
Negate:
XOR NegOne ; Flip all bits
ADDI 1 ; Add one
Abs_r:
RETURN
DisplayWithNeg:
CALL Abs
OUT Hex1
CALL Negate
OUT Hex0
RETURN
Mod6:
JZERO End
JNEG Mod6Neg
L: ADDI -6
JPOS L ; loops until number is negative / zero
JZERO End
EndPos:
ADDI 6
JUMP End
Mod6Neg:
ADDI 6
JNEG Mod6Neg ; loops until number is positive / zero
End:
RETURN
; Useful values
Zero: DW 0
NegOne: DW -1
One:
Bit0: DW &B0000000001
Bit1: DW &B0000000010
Bit2: DW &B0000000100
Bit3: DW &B0000001000
Bit4: DW &B0000010000
Bit5: DW &B0000100000
Bit6: DW &B0001000000
Bit7: DW &B0010000000
Bit8: DW &B0100000000
Bit9: DW &B1000000000
LoByte: DW &H00FF
HiByte: DW &HFF00
; IO address constants
Switches: EQU &H000
LEDs: EQU &H001
Timer: EQU &H002
Hex0: EQU &H004
Hex1: EQU &H005
Incr: EQU &H0F0
Quad: EQU &H0F1