Step-by-Step 8085 Simulator Tutorial: Writing Your First Assembly Program
This tutorial walks you through using an 8085 simulator to write, assemble, and run your first simple assembly program that adds two 8-bit numbers and stores the result in memory. I’ll assume a typical desktop 8085 simulator with an editor, assembler, registers view, memory view, and run controls (assemble/load, step, run, reset).
1. Goal and program overview
- Goal: Add 25 (0x19) and 37 (0x25) and store the 8-bit result at memory address 0x2000.
- Algorithm: Load first number into register A, add second number, store A into memory.
2. Typical 8085 instructions used
- MVI r, data — Move immediate data into register r (e.g., MVI A, 19H)
- ADD r — Add register r to accumulator A
- STA addr — Store accumulator into memory (16-bit address)
- HLT — Halt program execution
3. Complete assembly program
Paste this into the simulator editor exactly as shown (hex constants with H):
Code
ORG 2000H; set program start (optional, depends on simulator) MVI A, 19H ; load 0x19 (25) into accumulator MVI B, 25H ; load 0x25 (37) into register B ADD B ; A = A + B STA 2100H ; store result at memory address 0x2100 HLT ; stop execution
Notes:
- Some simulators expect ORG 0000H; others let you assemble anywhere. If your simulator auto-places code at 0000H, omit ORG or set it accordingly.
- Use uppercase hex with trailing H or simulator-specific notation (e.g., 0x19) depending on the tool.
4. Assemble and load
- Click the assembler/assemble button in the simulator.
- Fix any assembler errors (syntax, invalid directives). Common fixes: remove ORG if unsupported, ensure hex format matches the simulator.
- Load the assembled code into memory if your tool requires a separate load step.
5. Inspect registers and memory before running
- Open the registers pane (A, B, C, D, E, H, L, PC, SP, flags).
- Open memory view and navigate to address 2100H to watch the output location.
6. Run the program (step-by-step)
- Use single-step (or “Step Into”) to execute instructions one at a time. Observe:
- After
MVI A, 19H: A = 19H - After
MVI B, 25H: B = 25H - After
ADD B: A = 3EH (0x19 + 0x25 = 0x3E), flags updated (carry = 0) - After
STA 2100H: memory[2100H] = 3EH
- After
- Alternatively press Run/Execute to run until HLT; then inspect memory and registers.
7. Verify result
- Check memory at 2100H: it should contain 3EH (decimal 62).
- Check accumulator A: 3EH. Flags: Carry (CY) = 0 for this addition.
8. Modify exercise (optional)
- To add numbers stored in memory instead of immediate: load from memory using LDA/LDAX or MOV with register pairs, then add.
- To handle overflow for sums > 255, check CY flag or perform 16-bit addition using register pair HL and ADD with ADC.
9. Troubleshooting tips
- Assembler errors: verify hex notation and directives (ORG, END).
- Wrong addresses: confirm assembled load address and the address used in STA.
- Result not shown: some simulators require refreshing memory view after execution.
10. Next steps
- Try reading two numbers from memory, adding, and storing a 16-bit result using carry and register pairs.
- Practice conditional jumps (JZ, JNC) and loops to build more complex routines.
This simple program demonstrates the assemble–load–run cycle and basic 8085 operations. Apply the same step-by-step approach to experiment with other instructions and larger programs.
Leave a Reply