performanceassemblymachine-code8085code-size

Clock cycle and memory usage of an 8085 assembler program


I have this small little program written in assembly that squares a number.


Org 2010h
Db 0ah        

Org 2013h
Db 00h        

Org 1000h     
mvi a, 00h    
lxi hl, 2010h 

mov b, m
mov c, m      

CYCLE:
add b         
dcr c         
jnz CYCLE     

lxi hl, 2013h 
mov m, a       

hlt

I have a few questions regarding this program.

The first task is to determine the number of program memory cells necessary to store the program part in memory if each memory cell stores exactly a byte of information. The second task is to determine how many clock cycles are necessary to run the program.

What would be the logic here? How would I go about calculating these things? I don't understand this at all, any help would be appreciated. Cheers.


Solution

  • https://pastraiser.com/cpu/i8085/i8085_opcodes.html has instruction size and cycle times for every 8085 instruction.

    8085 being non-pipelined makes perf analysis pretty trivial: each instruction has a fixed cost you can just add up, unlike modern CPUs where a loop isn't just a sum of its parts.

    For example, my answer on Finding the absolute value of a number in 8085 microprocessor assembly language includes a code-size / performance analysis.

    or example: lxi hl, 2010h ---- 3 bytes and 10 clock cycles. mov b, m --- 1 byte and 7 clock cycles. And the sum of the two would be just 4 bytes and 7 clock cycles ? Is it that straightforward or am I missing something?

    I assume you mean 17 clock cycles, but yes, it's that easy within a basic block (no branching).

    8085 is so primitive it fully finishes executing one instruction before even fetching the next one.

    Of course as Erik pointed out, you have to trace execution through the loop to get the dynamic instruction count/mix: the jnz is taken 9 times and not-taken once.

    Code-size depends on static instruction mix (only counting each instruction once), but cycle time counts each instruction the number of times it's executed.