title: How can I display a diagonal line with a rainbow gradient in a 16-bit assembly simulator whose colours (in the source code) are in hexadecimal?
body: <p>I'm trying to <strong>programmatically</strong> display a line in a 16-bit assembly simulator with a <strong>rainbow gradient</strong> like in this picture:</p>
  <p><a href="https://i.stack.imgur.com/bSQNu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bSQNu.png" alt="Rainbow gradient I'm trying to achieve" /></a></p>
  <p>The online simulator I'm using is <a href="https://parraman.github.io/asm-simulator" rel="nofollow noreferrer">this one</a> and you can find the source code <a href="https://github.com/parraman/asm-simulator" rel="nofollow noreferrer">over here</a>.</p>
  <p>As we can see in the source code the colour palette is the following one:</p>
  <pre><code>const COLOR_PALETTE = [
  
      '#000000', '#000055', '#0000AA', '#0000FF', '#002400', '#002455', '#0024AA', '#0024FF', /* 0x00..0x07 */
      '#004800', '#004855', '#0048AA', '#0048FF', '#006C00', '#006C55', '#006CAA', '#006CFF', /* 0x08..0x0F */
      '#009000', '#009055', '#0090AA', '#0090FF', '#00B400', '#00B455', '#00B4AA', '#00B4FF', /* 0x10..0x17 */
      '#00D800', '#00D855', '#00D8AA', '#00D8FF', '#00FC00', '#00FC55', '#00FCAA', '#00FCFF', /* 0x18..0x1F */
      '#240000', '#240055', '#2400AA', '#2400FF', '#242400', '#242455', '#2424AA', '#2424FF', /* 0x20..0x27 */
      '#244800', '#244855', '#2448AA', '#2448FF', '#246C00', '#246C55', '#246CAA', '#246CFF', /* 0x28..0x2F */
      '#249000', '#249055', '#2490AA', '#2490FF', '#24B400', '#24B455', '#24B4AA', '#24B4FF', /* 0x30..0x37 */
      '#24D800', '#24D855', '#24D8AA', '#24D8FF', '#24FC00', '#24FC55', '#24FCAA', '#24FCFF', /* 0x38..0x3F */
      '#480000', '#480055', '#4800AA', '#4800FF', '#482400', '#482455', '#4824AA', '#4824FF', /* 0x40..0x47 */
      '#484800', '#484855', '#4848AA', '#4848FF', '#486C00', '#486C55', '#486CAA', '#486CFF', /* 0x48..0x4F */
      '#489000', '#489055', '#4890AA', '#4890FF', '#48B400', '#48B455', '#48B4AA', '#48B4FF', /* 0x50..0x57 */
      '#48D800', '#48D855', '#48D8AA', '#48D8FF', '#48FC00', '#48FC55', '#48FCAA', '#48FCFF', /* 0x58..0x5F */
      '#6C0000', '#6C0055', '#6C00AA', '#6C00FF', '#6C2400', '#6C2455', '#6C24AA', '#6C24FF', /* 0x60..0x67 */
      '#6C4800', '#6C4855', '#6C48AA', '#6C48FF', '#6C6C00', '#6C6C55', '#6C6CAA', '#6C6CFF', /* 0x68..0x6F */
      '#6C9000', '#6C9055', '#6C90AA', '#6C90FF', '#6CB400', '#6CB455', '#6CB4AA', '#6CB4FF', /* 0x70..0x77 */
      '#6CD800', '#6CD855', '#6CD8AA', '#6CD8FF', '#6CFC00', '#6CFC55', '#6CFCAA', '#6CFCFF', /* 0x78..0x7F */
      '#900000', '#900055', '#9000AA', '#9000FF', '#902400', '#902455', '#9024AA', '#9024FF', /* 0x80..0x87 */
      '#904800', '#904855', '#9048AA', '#9048FF', '#906C00', '#906C55', '#906CAA', '#906CFF', /* 0x88..0x8F */
      '#909000', '#909055', '#9090AA', '#9090FF', '#90B400', '#90B455', '#90B4AA', '#90B4FF', /* 0x90..0x97 */
      '#90D800', '#90D855', '#90D8AA', '#90D8FF', '#90FC00', '#90FC55', '#90FCAA', '#90FCFF', /* 0x98..0x9F */
      '#B40000', '#B40055', '#B400AA', '#B400FF', '#B42400', '#B42455', '#B424AA', '#B424FF', /* 0xA0..0xA7 */
      '#B44800', '#B44855', '#B448AA', '#B448FF', '#B46C00', '#B46C55', '#B46CAA', '#B46CFF', /* 0xA8..0xAF */
      '#B49000', '#B49055', '#B490AA', '#B490FF', '#B4B400', '#B4B455', '#B4B4AA', '#B4B4FF', /* 0xB0..0xB7 */
      '#B4D800', '#B4D855', '#B4D8AA', '#B4D8FF', '#B4FC00', '#B4FC55', '#B4FCAA', '#B4FCFF', /* 0xB8..0xBF */
      '#D80000', '#D80055', '#D800AA', '#D800FF', '#D82400', '#D82455', '#D824AA', '#D824FF', /* 0xC0..0xC7 */
      '#D84800', '#D84855', '#D848AA', '#D848FF', '#D86C00', '#D86C55', '#D86CAA', '#D86CFF', /* 0xC8..0xCF */
      '#D89000', '#D89055', '#D890AA', '#D890FF', '#D8B400', '#D8B455', '#D8B4AA', '#D8B4FF', /* 0xD0..0xD7 */
      '#D8D800', '#D8D855', '#D8D8AA', '#D8D8FF', '#D8FC00', '#D8FC55', '#D8FCAA', '#D8FCFF', /* 0xD8..0xDF */
      '#FC0000', '#FC0055', '#FC00AA', '#FC00FF', '#FC2400', '#FC2455', '#FC24AA', '#FC24FF', /* 0xE0..0xE7 */
      '#FC4800', '#FC4855', '#FC48AA', '#FC48FF', '#FC6C00', '#FC6C55', '#FC6CAA', '#FC6CFF', /* 0xE8..0xEF */
      '#FC9000', '#FC9055', '#FC90AA', '#FC90FF', '#FCB400', '#FCB455', '#FCB4AA', '#FCB4FF', /* 0xF0..0xF7 */
      '#FCD800', '#FCD855', '#FCD8AA', '#FCD8FF', '#FCFC00', '#FCFC55', '#FCFCAA', '#FFFFFF', /* 0xF8..0xFF */
  
  ];
  </code></pre>
  <p>And, as we can see annotated on it's side, we can access to those colours using a specific number (the array position). For example, we use '0' for defining black as it's the first colour in the array. Using Python I got an image showing me the colour organization of that array.</p>
  <p><a href="https://i.stack.imgur.com/bbVzc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bbVzc.png" alt="visual representation of the colour palette" /></a></p>
  <p>This is my take on colouring the diagonal but I want it to have a rainbow gradient:</p>
  <pre><code>colourDisplay EQU 0x300       ; Adress value for the visual display memory cell
  
  boot:
      MOV D, colourDisplay      ; Point register D to display output
      MOV C, 16                 ; Point register C to value 16
      MOVB BL, 8                
      JMP print                 ; Bring us to the print function
  
  print:
      MOVB [D], BL              ; Sets the colour into the display
      ADD D, 17                 ; We point to the next display cell in order to paint the next colours
      INCB BL
      DEC C                     ; C = C - 1
      JNZ print                 ; If we havent reach 0 in the counter (C) we jump to the beginning
      HLT                       ; Halt execution
  </code></pre>
  <p>That code displays this <strong>unwanted</strong> gradient:</p>
  <p><a href="https://i.stack.imgur.com/BOHoQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BOHoQ.png" alt="bad gradient" /></a></p>
  <p>It doesn't really matter if it's a diagonal or any other shape, I just want to achieve this reordering of the colour palette without modifying the source code.</p>