Principles of Computers 17th Lecture Pavel Ježek, Ph.D. pavel.jezek@d3s.mff.cuni.cz
... ?? $0000101A 00 SP + 10 07 $00001016 SP + 8 05 $00001014 09 SP + 4 $00001010 xx SP + 2 $0000100E SP → $0000100C procedure P1(a : word; b : longword); var loc1, loc2 : word; $0A50: SP := SP – (2+2) ... SP := SP + (2+2) ret begin push 00000007h push 0005h $0900: call 00000A50h $0905: SP := SP + (4+2) nop end. procedure argument b procedure argument a procedure prolog return address from procedure P1 to main program procedure body procedure epilog local variable loc1 local variable loc2
... ?? $0000101A 00 SP + 10 07 $00001016 SP + 8 05 $00001014 09 $00001010 SP + 2 $0000100E SP → $0000100C $00000B00 function F1(a : word; b : longword ) : word; var loc1, loc2 : word; $0A50: SP := SP – (2+2) ... SP := SP + (2+2) ret x : word; begin push 00000007h push 0005h $0900: call 00000A50h $0905: ($00000B00)^ := ? SP := SP + (4+2) nop end. procedure argument b procedure argument a ← IP begin ... end; return address from procedure P1 to main program local variable loc1 local variable loc2 x := F1(5, 7); global variable x
... ?? $0000101A 00 SP + 12 07 $00001016 SP + 10 05 $00001014 SP + 8 $00001012 09 $0000100E SP + 2 $0000100C SP → $0000100A $00000B00 function F1(a : word; b : longword ) : word; var loc1, loc2 : word; $0A50: SP := SP – (2+2) ... SP := SP + (2+2) ret x : word; begin push 00000007h push 0005h SP := SP - 2 $0900: call 00000A50h $0905: ($00000B00)^ := ? SP := SP + (4+2+2) nop end. procedure argument b procedure argument a ← IP begin ... end; reserved space for return value return address from procedure P1 to main program local variable loc1 local variable loc2 x := F1(5, 7); global variable x
... ?? $0000101A 00 SP + 12 07 $00001016 SP + 10 05 $00001014 SP + 8 $00001012 09 $0000100E SP + 2 $0000100C SP → $0000100A $00000B00 function F1(a : word; b : longword ) : word; var loc1, loc2 : word; $0A50: SP := SP – (2+2) ... (SP + 8)^ := retval SP := SP + (2+2) ret x : word; begin push 00000007h push 0005h SP := SP - 2 $0900: call 00000A50h $0905: ($00000B00)^ := ? SP := SP + (4+2+2) nop end. procedure argument b procedure argument a begin ... F1 := retval; end; reserved space for return value return address from procedure P1 to main program local variable loc1 local variable loc2 x := F1(5, 7); global variable x
... ?? $0000101A 00 SP + 4 07 $00001016 SP + 2 05 $00001014 SP → $00001012 09 $0000100E $0000100C $0000100A $00000B00 function F1(a : word; b : longword ) : word; var loc1, loc2 : word; $0A50: SP := SP – (2+2) ... (SP + 8)^ := retval SP := SP + (2+2) ret x : word; begin push 00000007h push 0005h SP := SP - 2 $0900: call 00000A50h $0905: (^word($00000B00))^ := SP^ SP := SP + (4+2+2) nop end. procedure argument b procedure argument a reserved space for return value x := F1(5, 7); ← IP global variable x
... 00 $00007A08 00 (00) 00 (20) $00007A04 $00007A02 $00007A00 B C3 $00002100 A $00002000 C2 0D F5 CALL E8 $00001306 7A 04 indir 15 FF $00001300 C1 $00001000 variable j program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. variable ptr padding variable i A procedure P2 procedure P1 B $00002100 ← $00002100 – ($001306 + 5) = $00002100 – $0000130B = $00000DF5 E8 = relative call (E9 = relative jump) main program $00007A04 C1 FF 15 = indirect call (FF 25 = indirect jump) C2
... ?? $00001306 CALL indir 15 FF $00001300 C1 $00001000 program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. A B ? main program ptr addr? C1 C2
... ?? $00001306 00 CALL indir 15 FF $00001300 C1 $00001000 program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. A B main program ptr addr? C1 C2
A C2 B C1 C1 C2 ?? $00002000 00 CALL E8 $00001306 indir 15 FF ... ?? $00002000 C2 00 CALL E8 $00001306 indir 15 FF $00001300 C1 $00001000 program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. A B P2 addr? main program ptr addr? C1 C2
... ?? $00007A00 B C3 $00002100 A $00002000 C2 00 CALL E8 $00001306 indir 15 FF $00001300 C1 $00001000 program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. A procedure P2 procedure P1 B P2 addr? main program ptr addr? C1 C2
... 00 $00007A08 00 (00) 00 (20) $00007A04 $00007A02 $00007A00 B C3 $00002100 A $00002000 C2 CALL E8 $00001306 indir 15 FF $00001300 C1 $00001000 variable j program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. variable ptr padding variable i A procedure P2 procedure P1 B P2 addr? main program ptr addr? C1 C2
B A C2 C1 B A C2 C1 A B C1 C2 00 $00007A08 00 (00) 00 (20) $00007A04 ... 00 $00007A08 00 (00) 00 (20) $00007A04 $00007A02 $00007A00 B C3 $00002100 A $00002000 C2 CALL E8 $00001306 indir 15 FF $00001300 C1 $00001000 ... 00 $00007A08 00 (00) 00 (20) $00007A04 $00007A02 $00007A00 B C3 $00002100 A $00002000 C2 0D F5 CALL E8 $00001306 7A 04 indir 15 FF $00001300 C1 $00001000 variable j program PascalProgram; type PProc = procedure; procedure P1; begin α end; jmp back = ret procedure P2; β var i : word; ptr : PProc; j : word; γ1 ptr := @P1; ptr; P2; γ2 end. variable ptr padding variable i A procedure P2 procedure P1 B P2 addr? main program ptr addr? C1 C2
Typical ISA Arithmetic Instructions MIPS: a := b op c x86, 6502: a := a op b
6502 Registers (Accumulator Architecture) 7 0 X 7 0 Y 7 0 S 0000 0001 7 0 P 7 0 PC 15 0 6502: 8-bit CPU with 16-bit logical and physical address spaces (1:1 mapping between logical and physical addresses, i.e. logical address = physical address)
Load Value Into Register (6502) LDA #$xx LDA $xxxx A := xx A := ($xxxx)^
Load Value Into Accumulator LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^
Load Value Into Accumulator LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDA ($xx,X) LDA ($xx),Y A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ A := ( (^word($00xx + X))^ )^ (^word($00xx))^ + Y
Load Value Into Register LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDX imm/addr LDY imm/addr A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ X := imm/addr Y := imm/addr 2 different variants implies 2 different OPCODEs for LDX! 2 different variants implies additional 2 different OPCODEs for LDY!
& Store Value From Register LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDX imm/addr LDY imm/addr STA $xxxx STA $xxxx,X STA $xxxx,Y STX addr STY addr A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ X := imm/addr Y := imm/addr ($xxxx)^ := A ($xxxx + X)^ := A ($xxxx + Y)^ := A addr := X addr := Y
Move (Transfer) Value Between Registers LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDX imm/addr LDY imm/addr STA $xxxx STA $xxxx,X STA $xxxx,Y STX addr STY addr A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ X := imm/addr Y := imm/addr ($xxxx)^ := A ($xxxx + X)^ := A ($xxxx + Y)^ := A addr := X addr := Y TAX TXA TAY TYA TSX TXS X := A A := X Y := A A := Y X := S S := X
Push To Stack & Pop (Pull) From Stack LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDX imm/addr LDY imm/addr STA $xxxx STA $xxxx,X STA $xxxx,Y STX addr STY addr A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ X := imm/addr Y := imm/addr ($xxxx)^ := A ($xxxx + X)^ := A ($xxxx + Y)^ := A addr := X addr := Y TAX TXA TAY TYA TSX TXS X := A A := X Y := A A := Y X := S S := X PHP PLP PHA PLA push P (flags) pop P (flags) push A pop A
Setting Flags LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDX imm/addr LDY imm/addr STA $xxxx STA $xxxx,X STA $xxxx,Y STX addr STY addr A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ X := imm/addr Y := imm/addr ($xxxx)^ := A ($xxxx + X)^ := A ($xxxx + Y)^ := A addr := X addr := Y TAX TXA TAY TYA TSX TXS X := A A := X Y := A A := Y X := S S := X 7654 3210 P N... ..Z. P.Negative := target.7 if target = 0 then P.Zero := 1 else P.Zero := 0; PHP PLP PHA PLA push P (flags) pop P (flags) push A pop A
Setting Flags LDA #$xx LDA $xxxx LDA $xxxx,X LDA $xxxx,Y LDX imm/addr LDY imm/addr STA $xxxx STA $xxxx,X STA $xxxx,Y STX addr STY addr A := xx A := ($xxxx)^ A := ($xxxx + X)^ A := ($xxxx + Y)^ X := imm/addr Y := imm/addr ($xxxx)^ := A ($xxxx + X)^ := A ($xxxx + Y)^ := A addr := X addr := Y TAX TXA TAY TYA TSX TXS X := A A := X Y := A A := Y X := S S := X 7654 3210 P N... ..Z. P.Negative := target.7 if target = 0 then P.Zero := 1 else P.Zero := 0; PHP PLP PHA PLA push P (flags) pop P (flags) push A pop A CLC SEC P.Carry := 0 P.Carry := 1
Bitwise Operations ORA imm/addr AND imm/addr EOR imm/addr ? NOT ASL A LSR A ROL A ROR A A := A BitwiseOr imm/addr A := A BitwiseAnd imm/addr A := A BitwiseXor imm/addr EOR #$FF A := A shl 1 A := A shr 1 A := A rol 1 A := A ror 1 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0;
Oring 16-bit Numbers (e.g. Little Endian) MSB of A stored at $A001 LSB of A stored at $A000 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 or MSB of B stored at $B001 LSB of B stored at $B000 B15 B14 B13 B12 B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 = MSB of C stored at $C001 LSB of C stored at $C000 C15 C14 C13 C12 C11 C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0
Oring 16-bit Numbers (e.g. Little Endian) MSB of A stored at $A001 LSB of A stored at $A000 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 or or LDA $A000 ORA $B000 STA $C000 LDA $A001 ORA $B001 STA $C001 MSB of B stored at $B001 LSB of B stored at $B000 B15 B14 B13 B12 B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 = = MSB of C stored at $C001 LSB of C stored at $C000 C15 C14 C13 C12 C11 C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0
Integer Operations 7654 3210 ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P N... ..ZC P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0;
Integer Operations (Adding 8-bit Numbers) 7654 3210 ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P N... ..ZC P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; LSB of A stored at $A000 A7 A6 A5 A4 A3 A2 A1 A0 carry + + LSB of B stored at $B000 B7 B6 B5 B4 B3 B2 B1 B0 = LSB of C stored at $C000 = C8 carry C7 C6 C5 C4 C3 C2 C1 C0 LDA $A000 CLC ADC $B000 STA $C000
Integer Operations (Adding 8-bit Numbers) 7654 3210 ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P N... ..ZC P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; LSB of A stored at $A000 A7 A6 A5 A4 A3 A2 A1 A0 carry + + LSB of B stored at $B000 B7 B6 B5 B4 B3 B2 B1 B0 Signed Integers? = LSB of C stored at $C000 = C8 carry C7 C6 C5 C4 C3 C2 C1 C0 LDA $A000 CLC ADC $B000 STA $C000
Adding 16-bit Numbers (e.g. Little Endian) MSB of A stored at $A001 LSB of A stored at $A000 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 + MSB of B stored at $B001 LSB of B stored at $B000 B15 B14 B13 B12 B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 = MSB of C stored at $C001 LSB of C stored at $C000 C15 C14 C13 C12 C11 C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0
Adding 16-bit Numbers (e.g. Little Endian) LSB of A stored at $A000 A7 A6 A5 A4 A3 A2 A1 A0 A15 A14 A13 A12 A11 A10 A9 A8 LSB of A stored at $A000 MSB of A stored at $A001 B7 B6 B5 B4 B3 B2 B1 B0 B15 B14 B13 B12 B11 B10 B9 B8 LSB of B stored at $B000 MSB of B stored at $B001 + = C7 C6 C5 C4 C3 C2 C1 C0 C15 C14 C13 C12 C11 C10 C9 C8 LSB of C stored at $C000 MSB of C stored at $C001 A7 A6 A5 A4 A3 A2 A1 A0 + LSB of B stored at $B000 B7 B6 B5 B4 B3 B2 B1 B0 = LSB of C stored at $C000 C8’ C7 C6 C5 C4 C3 C2 C1 C0 MSB of A stored at $A001 + A15 A14 A13 A12 A11 A10 A9 A8 + MSB of B stored at $B001 B15 B14 B13 B12 B11 B10 B9 B8 = MSB of C stored at $C001 C16 C15 C14 C13 C12 C11 C10 C9 C8
Adding 16-bit Numbers (e.g. Little Endian) LSB of A stored at $A000 ADC imm/addr A7 A6 A5 A4 A3 A2 A1 A0 carry result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 + + LSB of B stored at $B000 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; B7 B6 B5 B4 B3 B2 B1 B0 = LSB of C stored at $C000 = C8 carry C7 C6 C5 C4 C3 C2 C1 C0
Adding 16-bit Numbers (e.g. Little Endian) LSB of A stored at $A000 ADC imm/addr A7 A6 A5 A4 A3 A2 A1 A0 carry result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 + + LDA $A000 CLC ADC $B000 STA $C000 LSB of B stored at $B000 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; B7 B6 B5 B4 B3 B2 B1 B0 = LSB of C stored at $C000 = C8 carry C7 C6 C5 C4 C3 C2 C1 C0
Adding 16-bit Numbers (e.g. Little Endian) LSB of A stored at $A000 ADC imm/addr A7 A6 A5 A4 A3 A2 A1 A0 carry result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 + + LDA $A000 CLC ADC $B000 STA $C000 LSB of B stored at $B000 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; B7 B6 B5 B4 B3 B2 B1 B0 = LSB of C stored at $C000 = C8 carry C7 C6 C5 C4 C3 C2 C1 C0 MSB of A stored at $A001 + A15 A14 A13 A12 A11 A10 A9 A8 + MSB of B stored at $B001 B15 B14 B13 B12 B11 B10 B9 B8 = MSB of C stored at $C001 = C16 carry C15 C14 C13 C12 C11 C10 C9 C8
Adding 16-bit Numbers (e.g. Little Endian) LSB of A stored at $A000 ADC imm/addr A7 A6 A5 A4 A3 A2 A1 A0 carry result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 + + LDA $A000 CLC ADC $B000 STA $C000 LSB of B stored at $B000 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; B7 B6 B5 B4 B3 B2 B1 B0 = LSB of C stored at $C000 = C8 carry C7 C6 C5 C4 C3 C2 C1 C0 MSB of A stored at $A001 + A15 A14 A13 A12 A11 A10 A9 A8 + MSB of B stored at $B001 LDA $A001 ADC $B001 STA $C001 B15 B14 B13 B12 B11 B10 B9 B8 = MSB of C stored at $C001 = C16 carry C15 C14 C13 C12 C11 C10 C9 C8
Adding 16-bit Numbers (e.g. Little Endian) MSB of A stored at $A001 LSB of A stored at $A000 ADC imm/addr A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 + MSB of B stored at $B001 LSB of B stored at $B000 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; B15 B14 B13 B12 B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 = MSB of C stored at $C001 LSB of C stored at $C000 C15 C14 C13 C12 C11 C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0 LDA $A000 CLC ADC $B000 STA $C000 LDA $A001 ADC $B001 STA $C001
Integer Operations – Increments and Decrements (only X and Y) ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; unsigned numbers A := value – A P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; A := value – A A := value + (– A) P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? Two’s Complement? ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; unsigned numbers Negative number ↓ signed representation needed A := value – A A := value + (– A) P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? Two’s Complement? ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; unsigned numbers Negative number ↓ signed representation needed A := value – A A := value + (– A) How to represent non-negative number in two’s complement? P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? Via Two’s Complement ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 A := value – A ↓ NOT A INC A ADD value P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; Not a problem, that everything is in unsigned arithmetic A := value – A A := value + (– A) P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? Via Two’s Complement ADC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 A := value – A ↓ NOT A INC A ADD value A := value – A ↓ EOR #$FF CLC ADC #1 ADC value P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; A := value – A A := value + (– A) P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Integer Operations – Subtraction? Subtract with Borrow ADC imm/addr SBC imm/addr result := A + imm/addr + P.Carry P.Carry := result.8 A := result.7 … result.0 result := A – imm/addr – not(P.Carry) P.Carry := not(result.7) P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0; P.Negative := X/Y.7 if X/Y = 0 then P.Zero := 1 else P.Zero := 0; INX INY DEX DEY X := X + 1 Y := Y + 1 X := X – 1 Y := Y - 1
Shifts in More Detail ASL A oldA := A A.0 := 0 A.1 := oldA.0 LSR A ROR A ROL A oldA := A A.0 := 0 A.1 := oldA.0 A.2 := oldA.1 … A.7 := oldA.6 P.Carry := oldA.7 A.7 := 0 A.6 := oldA.7 A.5 := oldA.6 A.0 := oldA.1 P.Carry := oldA.0 A.7 := P.Carry Using Carry flag as “ninth” bit as well P.Negative := A.7 if A = 0 then P.Zero := 1 else P.Zero := 0;
No Division (div), No Mutiplication (*) Instructions on 6502
Instruction Timing