title: How can I add two bytes in Assembly if the sum of these two bytes exceeds a byte?
body: <p>I am studying the Assembly language in collage and I am pretty sure I don't understand anything, especially since the classes are online.</p>
  <p>This is probably a very simple question, but still, I don't know the answer. Suppose I want to add two numbers that I stored as bytes <code>a = 255</code> and <code>b = 255</code>. I don't think this works if we do this:</p>
  <pre><code>segment data use32 class=data
      a db 255
      b db 255
  
  segment code use32 class=code
      start:
      
          mov al, [a]
          add al, [b]
      
  </code></pre>
  <p>Since the sum is <code>510</code>, which cannot be stored in <code>AL</code> because <code>AL</code> is a 1 byte sized register, right? I tried this with NASM (which I have close to no clue as to how to use it) and I don't <em>think</em> I got the right answer. The EAX register looks like this at the end <code>0019FFFE</code>, and 510 in hexa is <code>1FE</code> so I suppose I should see a <code>1FE</code> somewhere, which we don't!</p>
  <p>So I guess that's not the right way. Then I tought that maybe I can use <code>AX</code> for the addition somehow. So I did something like this:</p>
  <pre><code>segment data use32 class=data
      a db 255
      b db 255
  
  segment code use32 class=code
      start:
  
          mov ax, word 0
          mov al, [a]
          add al, [b]
  </code></pre>
  <p>I tought that if we have initialized <code>AX</code> as 0 and then added something to <code>AL</code> that would result in a value that would exceed a byte, the result will propagate through <code>AX</code>, and we'd get the right answer. But I got <code>001900FE</code> at the end, so again there's no trace of a <code>1FE</code>.</p>
  <p>So how should I add these two values? I'm sorry if this is a stupid question, but I'm really confused. I retained close to nothing from class and the sources on the internet are very scarce when regarding Assembly, so I didn't really find the answer to my question online.</p>