bopsultra.blogg.se

Bresenham's line drawing algorithm
Bresenham's line drawing algorithm














Set_next_pixel is incomplete, and missing the return to caller. (Leaf functions - functions that don't call other functions - don't need to do this.) Usually this is handled by creating a stack frame and storing $ra there, in the non-leaf routines, then reloading $ra prior to returning to caller. Each time jal is used, it repurposes the $ra register, but each of these functions will need their own $ra value to get back to their caller.

bresenham's line drawing algorithm

Your static call chain has main calling line_to and line_to calling set_next_pixel, set_next_pixel calling set_color. Verify that memory is updated as you expect for store instructions.After each instruction, verify the control flow is correct for branches.After each instruction, verify that each register has the value you expect.Single step and follow the effect of each instruction.a horizontal line and/or a vertical line - maybe even a line of only 1 point in length. Start with the simplest possible test cases, e.g.Check the parameters are passed properly at the beginning of each function.(btw, +1 for having a written register-variable map.) Dynamic Debugging You can see that there is a mismatch between comments and code. Sub $s4, $s1, $t1 #s4 = y - cy # here s4 is dy, but comment above says s4 is xi Sub $s3, $s0, $t0 #s3 = x - cx # here s3 is dx, but comment above says s3 is dy

Bresenham's line drawing algorithm code#

Read the code and verify that each register named in the instruction corresponds to the proper variable in the algorithm. (The best way to do this is to write your pseudo code in C and actually run it.) Make sure your C/pseudo code algorithm actually works, otherwise debugging design problems in assembly is hard, when you're still learning assembly. Sra $t1, $t1, 5 # t1 contains number of wordsĮvery function besides line_to works fine, but I do not know what causes a problem in line_to. # number of bytes in a line: ((width + 31) / 32) * 4

bresenham's line drawing algorithm

# number of words in a line: (width + 31) / 32 Sw $v0, filesize($t0) # actual size of bmp file # pHeader - contains pointer to file buffer Or $t1, $t1, $t2 # set proper pixel to 1 (white) Xor $t1, $t1, $t2 # set proper pixel to 0 (black) asciiz "Incorrect color - should be 0 or 1"ĭescriptor. Unfortunately, when I complile my code, there is only pixel showing in a result.bmp file.eqv pHeader 0Ĭolor_err. I have read_bmpĪnd save_bmp functions, as well as function which sets color, function which draws a pixel and a function which draws a line. I need to draw a line on a 32x32 white/black image using Bresenham's line algorithm.














Bresenham's line drawing algorithm