How can I draw a line in assembly language without using decimal numbers?

  • Thread starter Thread starter alan_longor
  • Start date Start date
  • Tags Tags
    Line Method
Click For Summary

Discussion Overview

The discussion revolves around drawing a line in assembly language without using decimal numbers, specifically targeting the implementation on a frame buffer for a TV screen using AVR assembly. Participants explore methods for efficiently calculating pixel positions while avoiding decimal arithmetic.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks an efficient method to draw a line on a 320x200px monochrome frame buffer using assembly language without decimal numbers.
  • Another participant requests clarification on the type of frame buffer, the hardware setup, and the method of drawing the line, indicating a need for more context.
  • A participant describes the frame buffer's structure, noting that it takes 8000 bytes of SRAM, where each byte represents 8 pixels, and mentions using the SPI peripheral for data transmission.
  • There is a discussion about the inputs to the program, specifically the endpoints of the line, and the efficiency of the traditional line equation method (y = ax + b), which involves decimal calculations.
  • One participant suggests Bresenham's line algorithm as a potential solution, highlighting its use of fixed-point math to maintain precision without decimals.
  • Another participant notes the importance of using the same algorithm for erasing the line to ensure all pixels are addressed correctly.

Areas of Agreement / Disagreement

Participants express varying levels of understanding regarding the initial question, and while some suggest specific algorithms, there is no consensus on the best method to draw the line without decimal numbers. The discussion remains unresolved regarding the most efficient algorithm to use.

Contextual Notes

Participants mention limitations related to the need for efficient calculations without decimal handling, and the specifics of the hardware and frame buffer setup may influence the choice of algorithm.

alan_longor
Messages
29
Reaction score
3
i have a frame-buffer , and i want to draw a line using assembly language . i cannot work with decimal numbers . what's the best and most efficient method ?

thank you .
 
  • Like
Likes   Reactions: Rajesh Shirsagar
Engineering news on Phys.org
alan_longor said:
i have a frame-buffer , and i want to draw a line using assembly language . i cannot work with decimal numbers . what's the best and most efficient method ?

thank you .
Sorry, but I'm not tracking your question. What kind of "frame buffer"? What are you running your assembly language program on? What IO do you have? Where and how are you drawing a line? Physically on paper? On an LCD display? What kind of display?

Much more information and maybe some pictures or links would make it much easier to answer this for you... :smile:
 
  • Like
Likes   Reactions: Rajesh Shirsagar, BvU and Greg Bernhardt
berkeman said:
Sorry, but I'm not tracking your question. What kind of "frame buffer"? What are you running your assembly language program on? What IO do you have? Where and how are you drawing a line? Physically on paper? On an LCD display? What kind of display?

Much more information and maybe some pictures or links would make it much easier to answer this for you... :smile:

thank you for your attention Berkeman , i am using AVR assembly , and i am attempting to write this line on a TV screen , the frame buffer is 320x200px in size . it's monochrome so one bit represents a pixel . the protocol is PAL . and i am using an Atmega1284p .
i managed to get the protocol running and getting the image on the screen using interrupts . now i want to draw lines . storing things in memory and all is not a problem . since i can address any pixel on the screen easily , the problem now is in the method i will be using to draw the line . i want the most efficient way possible . the usual way "y= ax+b" is not efficient at all .

thank you .
 
alan_longor said:
thank you for your attention Berkeman , i am using AVR assembly , and i am attempting to write this line on a TV screen , the frame buffer is 320x200px in size . it's monochrome so one bit represents a pixel . the protocol is PAL . and i am using an Atmega1284p .
i managed to get the protocol running and getting the image on the screen using interrupts . now i want to draw lines . storing things in memory and all is not a problem . since i can address any pixel on the screen easily , the problem now is in the method i will be using to draw the line . i want the most efficient way possible . the usual way "y= ax+b" is not efficient at all .

thank you .
What is the format of the frame buffer? Can you post a link to it? How do you change the value of each pixel from OFF to ON? Or is there a grey scale number associated with each pixel? Is upper left on the display (0,0)?

What will the inputs to your program be? End points of the line? An equation like the one you mention? How often will the line image change? Will you be trying to move the line around on the display in real time?
 
berkeman said:
What is the format of the frame buffer? Can you post a link to it? How do you change the value of each pixel from OFF to ON? Or is there a grey scale number associated with each pixel? Is upper left on the display (0,0)?

What will the inputs to your program be? End points of the line? An equation like the one you mention? How often will the line image change? Will you be trying to move the line around on the display in real time?

the frame buffer takes 8000bytes of SRAM . every byte represents 8 pixels . every row is 40 bytes in size . i am using the SPI peripheral for this , since it can do automatic shifting quite fast . so i supply the byte to the SPI registers then set the transmission , this will get the needed data on the DATA OUTPUT pin of the SPI which will be fed to a register ladder . a 0 bit is black and 1 bit is white . at this point , the program only draws the line , that's it . then the interrupts will just continue supplying the correct signal in time using the set frame buffer . this is just a test program .
my problem is not technical , i need a good algorithm to draw the line .

thank you .
 
alan_longor said:
the frame buffer takes 8000bytes of SRAM . every byte represents 8 pixels . every row is 40 bytes in size . i am using the SPI peripheral for this , since it can do automatic shifting quite fast . so i supply the byte to the SPI registers then set the transmission , this will get the needed data on the DATA OUTPUT pin of the SPI which will be fed to a register ladder . a 0 bit is black and 1 bit is white . at this point , the program only draws the line , that's it . then the interrupts will just continue supplying the correct signal in time using the set frame buffer . this is just a test program .
my problem is not technical , i need a good algorithm to draw the line .

thank you .
That info helps a lot. But once you write the image into the frame buffer, you don't have to keep re-writing it, do you? Just when you want to draw a new line, right? And again, what will be the input to your program to tell you what line to calculate? Just the two endpoints?
 
berkeman said:
That info helps a lot. But once you write the image into the frame buffer, you don't have to keep re-writing it, do you? Just when you want to draw a new line, right? And again, what will be the input to your program to tell you what line to calculate? Just the two endpoints?
you only write the info once , you write it in the frame buffer . then the ISR code will continuously display the frames in time .
basically when interrupts are triggered after the sync of every horizontal line the code fetches row data from the correct addresses in the frame buffer at the end of the line there will be some extra time left that's when the ISR stops and the execution goes back to the main code .
exactly , the function get's the two points (x0,y0) (x1,y1) . normally i should find a = (y1 - y0) /(x1-x0) then b = y0 - a(x0) , then loop over this y=ax+b . but that involves decimal number handling and continuous division and multiplication which would be too slow and ineffective .

thank you .
 
https://www.google.com/?gws_rd=ssl#q=bresenham's+line+algorithm
The basic idea is calculate the nearest pixel center to the "ideal" location and any fractional over/under flow is maintained in an additional byte for the next calculation. Essentially fixed point math with the fractional part used only for the next calculation.

Also, when you need to erase the line, or part of it, you need to run the same algorithm with the same start and end points; otherwise you will miss a few pixels.
 

Similar threads

  • · Replies 102 ·
4
Replies
102
Views
4K
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
6
Views
3K
Replies
5
Views
3K
Replies
9
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 122 ·
5
Replies
122
Views
18K