Code

No Description


Upload Saved Program

Program Name:

Note that this is a testing release. Please contact me is you find any issues.

Session

Specific Memory Locations

Key Entry Queue

Cursor Keys

   
 
   

Keyboard ASCII Display

Keys

General Memory

Screen Memory

Colour Map

Screen ASCII Display

Code Memory

Top of Stack

Code

Last Instruction

Registers

Flags

Example Programs



There are a number of example programs which can be loaded in to illustrate how Assembly-Code can be written and run using this application.

Hello World

Displays the text Hello World.

It does this by copying the ASCII values for each character in "Hello World" into the screen memory.

Multiply

Multiplies together 7 and 12 and places the result in the accumulator.

It does this adding

Copy Text

Displays the text currently in the keyboard queue.

It does this by copying each value from the keyboard memory until 00 is reached into the corresponding location in the screen memory.

To Lower

Converts the text in the keyboad queue to lower case.

It does this by using the OR operator on the ASCII Value of each uppercase character.

Reverse

Reverses the text in the keyboard queue and displays in.

it does this by pushing each value onto the stack and then popping each value off and loading it into the display memory.

Blue Pixels

Displays all of the pixels that have both the blue bits set.

The 8-bit colour map is RRRGGGBB with the lower 2 bits used for blue. This program starts at with the value 3 and adds 4 to each value.

Colour Map

Copies the values from $0 (0) to 3F (63) into the Screen Memory to demonstrate the pixel colours that can be displayed.

The program then pauses. By pressing Run, the next set of colours are displayed.

Grey Scale

Firstly sets the Colour Filter to 0 to map the values onto the grey scale. Then Copies the values from $0 (0) to 3F (63) into the Screen Memory to demonstrate the pixel colours that can be displayed.

The program then pauses. By pressing Run, the next set of colours are displayed.

Dot

Move a dot around within the screen area.

Start by pressing "Run". The code stops running due to the BRK instruction. At this point the up, down, left or right cursor keys can be selected to move the dot around. The dot does not go outside the screen area.

Fill Stack

The number of values required on stack in entered using the keyboard buttons.

The value entered in converted to a single 8-bit value and stored in the accumulator. The values from 1 to this value are pushed onto the queue.

Prime Sieve

This sets the Screen Status to 3 to that 96 values can be used from general memory

The values from 0 to 95 are copied to general memory. Then, starting at 2, all values that are a multiple of the current number are set to 0.

. The program pauses until Run is selected again, when the next value is used.

The program stops after the value 9, leaving just the prime number in general memory.

Calculator

A Reverse Polish calculator that used the stack.

Only numbers from 0 to 9 can be specified, together with the operators + and -.

The current result can be between 0 and 255, and the value wraps round if the result is greater than 255 or less than 0.

Decimal to Binary

The keyboard buttons can be used to enter a vlaue between 0 and 255

The program converts this to binary.

Fibonacci Series

Calculated the values in the Fibonacci series

Does this by updating the values in the ADC commands.

Mini 6502 Activity/Assembler Language Simulator.

The Mini 6502 activity is based on the 6502 assembly language instruction set.

It is essentially a similator that uses a subset of the 6502 commands by limiting itself to just those that address zero page memory.

The purpose of the simulator is to demonstrate the simple functionality of the assmbler, how data input and output can be achieved and how memory can be updated, including that of the instruction set.

All values use just eight bits, taking values from 0-255 (decimal) or $00-$FF (hexadecimal).

Values from 128-255 are used to represent the negative values -128 to -1.

Code Entry

Code is entered by selecting an assembler command. If an operand is required, then its value and the addressing mode are specified at the next stage.
Operand types: Addressing Modes (All 8-bit)
  • Implied: Does not require an operand
  • Accumulator: Uses the accumulator
  • Immediate: Uses value specified
  • Zero-Page: Direct Addressing on. The value used is the contents of the specified memory location
  • Offset-X: indexed Addressing on zero-page memory. Value used is the contents of the specified memory location offset by the value in the X register.
  • Offset-Y: indexed Addressing on zero-page memory. Value used is the contents of the specified memory location offset by the value in the Y register.
  • Indirect X: Indexed Indirect Addressing. The memory address used is the value in the specified memory address offset by the value in the X register. The value used is the contents of this memory location (Indirect Addressing for LDA command only)
  • Indirect Y: Indexed Indirect Addressing. The memory address used is the value in the specified memory address. The value used is the contents of this memory location offset by the value in the Y register(Indirect Addressing for LDA command only)
  • Relative: This is the relative offset to jump to in the code. It is specified using a predefined label and is calcualted by subtracting the location of the label from that of the current instruction.
  • Label Name: A label name used to specify a position in the code. It does not appear in the session code but is used to calculat the relative offset. Branch instructions requiring a label operand are only enabled once at least one label has been defined

Session

The session tab displays the memory map, options to enable input to a program, options to illustrate how data can be displayed, the code, the last instruction, register values and the flags

Key Entry

  • A small number of key buttons can be used to enter ASCII keyboard values into the are of memory assigned as the Key Entry Queue.
  • The start and the end of the Key Entry Queue are stored in the memory locations $2C and $2D.
  • The last key entered is stored in the memory location ($2C + 1). It is also stored in the memory location 2E
  • The last cursor key to be selected is stored in memory location $2D
  • If the code contains a single BRK statement, the code will start running again when a key is selected

Screen Display

  • Values entered into the Screen Memory $40 - $7F is mapped to a pixel display and to an ASCII character display
  • The pixel display the value as an 8-bit colour. 8-bit colour uses 3 bits for red, 3 bits for green and 2 bits for blue. for example 11111100 ($FC) represents bright yellow.

Registers

  • Accumulator: Used by most of the commands. It's contents is used as an operand and it is also used to store the result of calculations
  • X-Register: Used as a counter or a memory offset.
  • Y-Register: Used as a counter or a memory offset.
  • Program Counter: Contains the memory location of the current instruction. Cannot be modified by the commands
  • Stack Pointer: Records the memory location of the top of the stack

Flags

The values 0-127 represent positive value and 128-255 represent negative values.
  • Carry Flag (C): Set when the result of an operation is greater than 255
  • Negative Flag: This is set if the result is negative
  • Overflow Flag (V): this flag is set if a calculation on two positive values results in a negative value or a calculation on two negative values results in a positive value.
  • Zero Flag (Z): This is set is the result of a calculation is 0
Example Calculation: 23 represents the positive value 23. 240 represents the negative value -16. Adding the two values, 23 + 240 = 263. As the result is greater than 255, then 256 is subtracted from it giving a value of 7. This is as expected since 23 + (-16) = 7.
As the result exceeded 255, then the carry flag is set. However the overflow value is not set as the actual calculation or 23 - 16 does not result in an overflow.

Memory Map

The memory is made up of 255 locations that are used for the code and data store.


Specific Memory Locations

There are four types of memory location

  • 00 - 05: Store information relating to the keyboard entry. They can be overwritten but will be updated when the next related keyboard button is selected.
  • 06, 07, 0C: Store the location of the start of the main memory blocks. They can be used with inderect addressing to locate the required memory locaiton. If overwritten, the new value is not altered.
  • 08 - 0A: Determines how the screen memory is displayed. These are not updated when a program is run unless the value is specifically altered by the program.
  • 0B - 0F: Store information relating to the program and are updated after each relevant instruction.

00:

Stores the location of the front of the keyboard queue

01:

Stores the location of the back of the keyboard queu

02:

Stores the value of the last key entered

03:

Stores the value of the previous key entered

04:

Stores the value of the last cursor key entered. 1 - Up, 2 - Right, 3 - Down, 4 - Left

05:

Stores 1 if Caps Lock on and 0 otherwise. Determines whether the letters in the keyboard entry are in uppercase or lowercase

06:

Stores the location of the start of general memory. Can be used with indirect addressing

07:

Stores the location of the start of screen memory. Can be used with indirect addressing

08:

The value determined which screen elements are displays. 1 - No Screen ASCII display. 2 - No Colour Map. 3 - No screen elements with the screen memory becoming part of the general memory

09:

The value determines the colour filter that is applied to the colours displayed in the colour map. The represents an 8-bits colour value that is mapped to the required colour (RRRGGGBB)

0A:

The value determines the colour that the non-zero memory values are highlighted with. The represents an 8-bits colour value that is mapped to the required colour (RRRGGGBB)

0B:

Stores the number of values on the stack

0C:

Stores the location of the start of code memory. Can be used with indirect addressing

0D:

Stores the address of the current instruction

0E:

Stores the value of the operand of the current instruction

0F:

Stored the value of the status register. The status register is an 8-bit value based on the current flag values (NV-B--ZC)

Ranges of memory locations that can be used for a specific purpose have been grouped together


Location

Detail

Start

End

$10 (16)

$1F (31)

Key Entry Queue

Used as a circular quere for the keyboard input, enable a program to dynamically read in data.

$20 (0)

$3F (63)

General Memory

An area that can be used to store working data

$40 (64)

$7F (127)

Screen Memory

Data in this area is displayed as an 8 by 8 pixel, using a simple RBG mapping between the location values and the colours. The ASCII values of each location is also mapped to the related character and displayed

$80 (128)

$FF (255)

Code Memory

This is where the code is store. Each assembly command consists of two bytes. If a command starts with 00, then this is consistered to be the end of the code.

$100 (356)

$1FF (511)

Stack Memory

This is a separate area of memory that is used as the stack. It is outside of zero page memory and cannot be overwritten using any memory related assembler commands.
Only the rows of memory that are required are displayed.

Commands

The following 6502 Assembler Commands can be used in this similator. The address modes that have been implemented are also listed together with the resulting machine code value.

Command

Detail

Operator

Address Mode

Machine Code

 

ADC

Immediate

$69

Add with carry. A = A + M + C (Mod 256). Flags initially cleared.
  • Carry flag set if (A + M + C) is greater than 255
  • Negative flag is set if result is greater than 127
  • Overflow flag set if result of actual calculation caused an overflow.
  • Zero flag is set if result is 0.

Zero-Page

$65

   

Offset-X

$75

   

AND

Immediate

$29

Logical And. A = A AND M. (0011 AND 0101 = 0001)
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$25

   

Offset-X

$35

   

ASL

Assembler

$0A

Arithmetic shift left. A = A x 2. (11110000 -> 11100000 C = 1)
  • Carry flag set if result is greater than 255
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$06

   

Offset-X

$22

   

BCC

Relative

$90

Branch on carry clear to the relative offset.

BCS

Relative

$B0

Branch on carry set to the relative offset.

BEQ

Relative

$F0

Branch on result zero to the relative offset.

BMI

Relative

$30

Branch on result negative to the relative offset.

BNE

Relative

$D0

Branch on result not zero to the relative offset.

BPL

Relative

$11

Branch on result positive to the relative offset.

BRK

Implied

$00

Forced Interupt

BVC

Relative

$50

Branch on overflow clear to the relative offset.

BVS

Relative

$70

Branch on overflow set to the relative offset.

CLC

Implied

$18

Clear carry flag.

CLV

Implied

$B8

Clear overflow flag.

DEC

Zero-Page

$C6

Decrement accumulator by one.

Offset-X

$D6

   

DEX

Implied

$CA

Decrement X Register by one.

DEY

Implied

$88

Increment Y Register by one.

EOR

Immediate

$49

Logical Exclusive Or. A = A XOR M. (0011 XOR 0101 = 0110)
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$45

   

Offset-X

$55

   

INC

Zero-Page

$E6

Increment accumulator by one.

Offset-X

$F6

   

INX

Implied

$E8

Increment X Register by one.

INY

Implied

$C8

Increment Y Register by one.

LDA

Immediate

$A9

Load A from memory.
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$A5

   

Offset-X

$B5

   

Indirect X

$A1

   

Indirect Y

$B1

   

LDX

Immediate

$A2

Load X from memory.
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$A6

   

Offset-X

$B6

   

LDY

Immediate

$A20

Load Y from memory.
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$A4

   

Offset-X

$B4

   

LSR

Assembler

$0A

Logical shift right. A = A DIV 2. C = A MOD 2. (00001111 -> 000001111 C = 1)
  • Carry flag set to right-most digit
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$06

   

Offset-X

$22

   

ORA

Immediate

$09

Logical Or. A = A OR M. (0011 OR 0101 = 0111)
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$05

   

Offset-X

$15

   

PHA

Implied

$48

Push accumulator onto stack.

PLA

Implied

$68

Pull accumulator off stack.

ROL

Assembler

$2A

Rotate memory one bit left. (11110000 -> 11100001 C = 1)
  • Carry flag set if result is greater than 255
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$26

   

Offset-X

$34

   

ROR

Assembler

$6A

Rotate memory one bit right. (00001111 -> 100000111 C = 1)
  • Carry flag set to right-most digit
  • Negative flag is set if result is greater than 127 and cleared otherwise
  • Zero flag is set if result is 0 and cleared otherwise

Zero-Page

$66

   

Offset-X

$24

   

STA

Zero-Page

$85

Store A to memory.

Offset-Y

$95

   

STX

Zero-Page

$86

Store X to memory.

Offset-X

$96

   

Indirect X

$81

   

Indirect Y

$91

   

STY

Zero-Page

$84

Store Y to memory.

Offset-X

$94

   

SBC

Immediate

$E9

Subtract with carry. A = A - M - (1 - C) (Mod 256). Flags initially cleared.
  • Carry flag set if (A - M - (1 - C)) is less than 255
  • Negative flag is set if result is greater than 127
  • Overflow flag set if result of actual calculation caused an overflow.
  • Zero flag is set if result is 0.

Zero-Page

$E5

   

Offset-X

$F5

   

SEC

Implied

$38

Set carry flag.

TAX

Implied

$AA

Transfer A to X.

TAY

Implied

$A8

Transfer A to Y.

TXA

Implied

$8A

Transfer X to A.

TYA

Implied

$98

Transfer Y to A.