DEV Community

A Serputov
A Serputov

Posted on • Edited on

Software Portability and Optimization

Introduction

Today, I will discuss my first experience working on 6502 Emulator.

The 6502 is an 8-bit processor with a 16-bit address bus. It is, therefore, able to access 64 kilobytes (216 bytes). Since each 16-bit address is comprised of two 8-bit bytes, memory can be viewed as 256 pages of 256 bytes each.

We have two tasks to do:

Calculate how long it takes for the code to execute, assuming a 1 MHz clock speed?

Calculate the execution time of the fastest version of this program that you can create?

Calculate how long it takes for the code to execute, assuming a 1 MHz clock speed?

First of all, below, you can see the code I'm about to work with and count how long it takes to execute it.

    lda #$00    ; set a pointer at $40 to point to $0200
    sta $40
    lda #$02
    sta $41

    lda #$07    ; colour number

    ldy #$00    ; set index to 0

loop:   sta ($40),y ; set pixel at the address (pointer)+Y

    iny     ; increment index
    bne loop    ; continue until done the page

    inc $41     ; increment the page
    ldx $41     ; get the current page number
    cpx #$06    ; compare with 6
    bne loop    ; continue until done all pages
Enter fullscreen mode Exit fullscreen mode

To calculate this code, we will need special docs with the time of each command execution.

I've decided to share my calculation via a photo of excel because it seems more informational.
Image description

Calculate the execution time of the fastest version of this program ?

I tried to optimize code and decided to see how different our professor did the same work in class. Code below.

    LDA #$00
    STA $10
    LDY #$02
    STA $11

    LDA #$07
    LDY #$00    

LOOP:   STA ($10),Y
    INY 
    BNE LOOP

    INC $11
    LDX #$06
    CPX $11
    BNE LOOP
Enter fullscreen mode Exit fullscreen mode

I didn't find what I could change to make the first code faster, but I think this code can execute in fewer cycles after I did small calculations.

Conclusion

While working on these experiments, I did solve a minor bug in Assembly Compiler. See the Link to the pull request.

⚠️ Open Source For Developers Blog Post: Link

Links

🖇 git https://github.com/aserputov
🖇 twitter https://twitter.com/aserputov\

p.s This post was made for my SPO class Lab 2 assignment

Top comments (0)