Exploring Assembly Language (Lab-1)
Introduction: In the realm of computer programming and analysis, delving into assembly language can be both daunting and exhilarating. As a student at Seneca in computer programming and analysis, I recently embarked on a lab journey exploring the intricacies of assembly language, particularly focusing on the 6502 architecture. In this blog post, I'll share my experiences, discoveries, and insights gained from the lab experiments.
Calculating Performance and Modifying Code: In one of the lab experiments, I initially tackled the task of calculating the execution time of a code snippet aimed at filling a bitmapped display with a solid color. After analyzing the code and considering a clock speed of 1 MHz, I calculated the execution time to be approximately 1.321 milliseconds. This involved dissecting the assembly code, understanding the purpose of each instruction, and considering optimization techniques.
Here is the original code : lda #$00 ; Load accumulator with low byte of memory address
sta $40 ; Store accumulator into memory address $40 (low byte of pointer)
lda #$02 ; Load accumulator with high byte of memory address
sta $41 ; Store accumulator into memory address $41 (high byte of pointer)
lda #$07 ; Load accumulator with color number
ldy #$00 ; Set index to 0
loop: ; Start of loop
sta ($40),y ; Set pixel color at the address (pointer)+Y
iny ; Increment index
bne loop ; Continue until done the page (256 pixels)
inc $41 ; Increment the page
ldx $41 ; Get the current page number
cpx #$06 ; Compare with 6
bne loop ; Continue until done all pages
The code operates by setting a pointer in memory to define the starting position of the display. It then iterates through each page of the display, setting pixel colors sequentially. The execution time was calculated based on the number of clock cycles required for each instruction.
Optional Sections: As part of the lab, I experimented with several optional sections to further explore the capabilities of assembly language.
Random Color Generation: I implemented a pseudo-random number generator to assign random colors to each pixel on the display. This added an element of unpredictability and visual interest to the output.
Here is the code for the output : ;
lda #$42 ; Seed value (can be any non-zero value) sta $43 ; Store seed in memory address $43 ; Loop through each pixel and assign a random color lda #$00 ; Load accumulator with low byte of memory address sta $40 ; Store accumulator into memory address $40 (low byte of pointer) lda #$02 ; Load accumulator with high byte of memory address sta $41 ; Store accumulator into memory address $41 (high byte of pointer) ldy #$00 ; Load index register Y with 0 loop: lda $43 ; Load seed from memory address $43 clc ; Clear carry flag adc #$69 ; Add an arbitrary value to seed sta $43 ; Store updated seed back into memory address $43 lda $43 ; Load seed from memory address $43 and #$FF ; Mask out higher bits- sta $44 ; Store masked seed in memory address $44
Experiences and Reflections: . Working with assembly language provided a deeper understanding of low-level programming concepts and the inner workings of computer hardware. Analyzing and optimizing code for performance highlighted the importance of efficiency in software development.
One of the most valuable lessons from this lab was the importance of attention to detail and precision. Assembly language requires meticulous planning and execution, but the results can be incredibly satisfying.
Comments
Post a Comment