Reputation: 1
I know how to draw horizontal lines by doing
LOOP1 STR R5, #0 ;starting ixel
ADD R5, R5, #1 ;increment of pixel on coordinate
ADD R7, R7 #-1 ;decrement to the desired length counter
BRp LOOP1 ;keeps looping until register with desired length is zero
Obviously the registers will be different for whatever the user chooses for the counter and coordinate locations but these were just numbers from my previous code. What would be a way to manipulate that code to draw a vertical line? I'm not completely comfortable with the formatting of the code on this website yet either so please excuse me if I am wrong in a few areas.
Upvotes: 0
Views: 631
Reputation: 26656
The difference between horizontal line and vertical line is how we increment the pixel position.
Let's note that a two dimensional coordinate can (and must) be mapped to a one dimensional system by a formula like rowCoordinate * columSize + columnCoordinate
. (Memory is a one-dimensional system, it doesn't have two dimensions so we use this kind of mapping.)
So, as you have shown, we can draw a horizontal line by traversing each pixel from (row,0) to (row,columnSize-1). By the mapping formula above, we go from
(row,c) to (row,c+1) by simply adding 1 to the address of the pixels.
To draw a vertical line, we want to vary the row position and keep the column position fixed as in: from (0,col) to (rowSize-1,col).
According to the mapping of 2d to 1d, that means going from
(r,col) to (r+1,col) we need to increment by columnSize instead of 1.
Upvotes: 0