TürkçeEnglish

 

Download
Freeware
Shareware
Sample Programs
User Manual

 

MICROPROCESSOR SIMULATOR

[editor][assembler][debugger][animator][virtual applications][examples]

 

Microprocessor Training Set

Visual6502

General Overview

The Visual Simulator supplies, debugging errors (which occurs at present or during working) and watching assembly programs working (which are written in assembly language) in a visual way after compiling in an assembler. In Visual Simulator there are editor, assembler, debugger, animator and virtual application units.

Users can write programs in assembly language for 6502 microprocessor at settled editor. They can assemble it (in assembler) and watch working process in simulator (in debugger). If requires they can watch how programs (their own program or ready program) were worked by microprocessor (in animator). Users can control some devices visually like Input and output ports (PIA A and B ports) leds, micro-switches, traffic lamps and 7 segment display.


When main window opens there are upper menus, menu bar and tool bar. Tool bar separates five main groups. Tools, which are settled upper left side, are related in file processing. Tools, which are lower left side, are related in window opening. From the beginning of the left side there are disassembler icon to show machine codes and icons which show register contents and a program log icon which shows different memory locations (0. page data segment, 1. page stack segment, 2. page program segment) and keeps registers and codes present values.

The Editor

Editor is a window, which was opened from file menu or main menu and used for writing programs for 6502 microprocessor in assembly language. Result of selection causes a free editing window opening. The assembly program that was written in editor can be kept in .asm extension and can be opened and edit. In upper side of the editor window there is name and path of working program. The left side of the editor is used for putting breakpoint. There is a red circle appears in the breakpoint line.

The Assembler

The program that is written in editor was loaded to memory its codes are not assembled. With selection of Assembler button program occurs with its command codes in another window. In program window there are address (hex), command codes (two section), program and explanations. Program that was assembled can be kept in hex extension. In hex window direct addresses are settle down instead of address labels. When comparing addresses this supplies easiness to programmer. This window was reached from tools section in main menu with pushing disassemble button.

.DATA $20

VALUE .BYTE $25,45,$5A,00

TAB .BYTE 15,20,25,"COSMOS"

Yukarıdaki tanımlamayla, veri bölümünde bir dizi baytlık hex veya ondalık veya string veriler yerleştirilmiştir. VALUE ve TAB etiketli adreslere bu veriler sıralanmıştır. .DATA'nın yanındaki $20 ifadesi altındaki verilerin bellekte yerleşeceği orijin noktasını verir.

Program alanına yerleşecek kodların tanımlanması .CODE Adres ifadesi ile yapılır. Kodlar bellekte hangi adresten itibaren yerleşecekse .CODE'nin yanına o adres yazılır.

.CODE $0200

LDA #$25

ADC VALUE

STA VALUE+3

BRK

Burada .BYTE ifadesi kendinden sonra gelecek verinin bayt cinsinde olduğunu gösterir. 6502 mikroişlemcisi 8-bitlik bir işlemci olduğundan verilerin tanımlanmasında sadece BYTE talimatı yeterli olacaktır.

The Debugger

When Debugger button was pushed units, registers, data fields, program fields and stack fields which helps programmer to debugging are open. Then program was worked step-by-step or normally and observed. Debugger was controlled with buttons above. Button at the left side is used for operating program continuously it’s own speed. In this speed program was not watched. Second button is used for operating program step-by-step. To operate program this button was pushed by mouse or space bar button in keyboard. It is user dependent button in program watching that’s why it is the most ideal choosing. Third button is used for operating program step-by-step but in a defined speed. Speed can be set from simulation\alternatives in pull down menu.

Button at the right side is used for stop program when ever you want at the same time this button can be used for stop point. Button which is second from right is used for reset and restart program.

REGISTER WINDOW

This window shows content of PIA I/O registers and 6502 microprocessor’s registers which programmer can watch during program work. Microprocessor registers A,X,Y are general purpose, PC,SP and flags are special purpose registers. Flags in registers are N (negative), V (oVerflow), B (Break), D (Decimal), I (Interrupt), Z (Zero) and C (Carry) the eighth register is invisible for future using.


Registers, which were used in A, and B ports in 6502 or 6820 are also in this window under PIA. Dataset, which were loaded to these ports, were seen in this window at the same time.

Memory Field Window

In 6502 microprocessor memory was separated 256 pages, every page occurs 256 byte. Separating pages supplies more easy arrival to data. The first page of memory that is to say zero page (0000-00FF) was planned as a data field. If a page includes 256 byte data, extra dataset can be located empty pages. In this microprocessor second page was reserved as a stack field. In this section hex response dataset, which was declared at the beginning of the program, was seen with its ASCII response.


Stack Pointer (SP) shows the end of (01FF) this address field (0100-01FF) directly. Every data, which was loaded to stack, decreases its value one (01FE) and this goes so that finish of this field.

Second page was used to write program codes. In 6502 microprocessor program usually starts from 0200 address (CODE $0200 or ORG $0200). Codes, which converted to machine code, can be seen from this window. At the same time you can see every code’s ASCII response from right side of this window.

In memory windows, program field starts from .CODE $XXXX which was given at the beginning of the program. Data field was seen from the beginning of the address which starts with .DATA $XXXX Binocular button can be used for choosing an address field, which is out of these addresses.

The Animator

When animator button in simulator window was pushed monitor was cleaned and a new image was done. In this image there are microprocessor registers, internal and external communication ways, address solving units, memory (RAM and ROM) and PIA I/O units.

Control console has been planned as three sections. In present process section working programs hex codes (machine codes) can be seen lightened. In state section program get command code, solve code and operate can be seen. If a section was lightened it means program is working in this phase. Control section checks program working. The bar, which is lower right side, is speed bar. Speed can be changed while program is running. The switch, which is right side, was used to exit from animator.

The green fields in animator show address lines, cream-colored fields show data lines, thin grey and yellow fields which were connected to grey show control lines. Thick lines show internal communication lines.

When program working in animator a red block is moving in data lines according to command. The red block, which is moving on green field, means an address data is going from one unit to another. Lightened unit means “this unit is active now”. The red block, which is moving in cream-colored fields, show a data is going from one unit to another. Again lightened unit shows “this unit is active now”. Lightened grey and yellow lines mean, “Unit, which will process, is trigging”.

Virtual Application

Here a series of application, which were applied in microprocessor application set, was shown virtually in simulator. Applications;

1) LED (16 unit, 8 with A port and 8 with B port) indicators,
2) 7-segment display, 6 unit,
3) Traffic Lamps (For watching T type crossroads)
4) Micro-switches (can be connected to A and B ports 8 unit)



Programs can control these devices according to 0400 and 0403 PIA I/O setting. When programs come across this addresses they do necessary things with an intelligent process. Users can use this registers in their own program with their addresses or their nick names (CRA, DDRA, ORA and CRB, DDRB, ORB).

In PIA programming 0400, 0401, 0402 and 0403 were reserved to registers. 0401 was reserved for CRA, 0403 was reserved for CRB, 0400 was shared between DDRA and ORA. This sharing were done with the second bit of CRA. When second bit is zero this mean DDRA was selected, when it is 1 ORA was selected. In B port 0403 CRB, 0402 was shared between DDRB and ORB. Sharing was done with second bit like A port.

With setting mentioned ports, control elements, which was connected to A and B ports, can be controlled easily.


Examples

ASSEMBLER DIRECTIVES

In Assembly language program writing two order word were used. One of them is commands. Commands are a short description of order word which tell microprocessor what to do. Second order words were named as directives. These give orders only to assembler. In other words a shortening of order words which were used to help sending order words to microprocessor.

When assembling an assembly program with assembler, assembler adapts memory allocation and various label names to their real names according to directives and leaves command codes to microprocessor.

Command Segment Directives

.CODE <address>

With this definition assembler declare that program will be located from the beginning of the <…….> address. Command lines must be started after that expression.

  .CODE $0200
START LDA   $20
  ADC   #05
  STA   $21
  BRK

Address which is after “.CODE” instruction means that command codes will be located from the beginning of 0200 address.

Data Segment Directives

.DATA $20

This directive shows that dataset will be located in the memory from the beginning of the 0200. This determines dataset which was used by program. Data segment can be declared lots of times according to programmer’s wish.
.DATA $20

VALUE .BAYT $25, 45, -23, $5F

.DATA $5050

START .BYTE $AA, 89, $C5

In data directives data can be given decimal or hexadecimal. If nothing was written in front of the number and number is little than 255 than it was accepted decimal. If there is a $ sing in front of the number, it’s right hand value between 0 and F and at most two column (registers are 8-bits) than this was excepted as hexadecimal.

Other Definitions

In program writing labels, which was used to declare address, can be written in upper case, lower case or Turkish but it wasn’t recommended to use Turkish characters in program.

Labels, which were used in program, must be at most eight character and case insensitive. Label must start a letter after those numerical characters can be used. Some kinds of examples are below:

Start
START
A123SA
ADD_T

In labels there mustn’t include any blank. Blank shows parts between label, command and operand.

There must be at least one blank between label, command and explanations. Explanations must start with (;). Explanations can be written in command line or in a line with which starts a (;).

.BYTE Directives

6502 microprocessor has 8-bits data lines and registers for that reason dataset in data fields were declared as bytes. Dataset as bytes must start with .BYTE instruction. String data can be defined with .BYTE instruction if desired. Comma must be put at the start and end of the string.

Message .BYTE "This time OK"

END Directives

This instruction declares to assembler that the program was finished. This must be put at the end of the program.


PROGRAM EXAMPLES 1.

; Uses subroutines and interrupts
  .CODE $0200    
START LDA  #$55    
  SEC    
  SBC  #05    
  JSR   SAP    
  LDA  #$CC    
  TAX    
  TXS    
  JSR   SAP    
  LDX  #$AA    
  JMP  START    
  BRK    
       
SAP LDX  #05    
DEV NOP    
  DEX    
  BNE  DEV    
  RTS    
;This section is about Nonmaskable Interrupt
NMI LDA   #00    
  STA   CRA    
  LDA   #$FF    
  STA   DDRA    
  LDA   #04    
  STA   CRA    
  LDA   #0    
NEW INC   ORA    
  BMI   BACK    
  JMP   NEW    
BACK RTI    
;This section is about Interrupt Requet
IRQ LDA   #00  
  STA   CRB
  LDA   #$FF
  STA   DDRB
  LDA   #04
  STA   CRB
  LDA   #$CC
  STA   ORB
  LDA   #$33
  STA   ORB
  RTI
       
;IRQ interrupt vector address
  .CODE $F3A9    
  JMP IRQ    
;NMI interrupt vector address
  .CODE $F3A6    
  JMP NMI    
       
;RES interrupt vector address
  .CODE $F319    
  JMP $0200 ; return to the starting adres of the program
       
  END ;end of program  
       
       
       

In this program codes which were written between .CODE $0200 and BRK do some subtract, move and subroutine calls. Commands which are after RTS (Return From Subroutine) shows that where will program go if someone pushes interrupt buttons.

When program is running in simulator if someone pushes IRQ button an interrupt request was made. In this time I flag was seen if this flag is 0 interrupt accepted and program jumps F3A9 address process NOP command and go back with RTI command. Every interrupt program must use RTI command otherwise program process mix.