title: Multiplying two values and printing them to the screen (NASM, Linux)
body: <p>I keep reading that in order for one to perform integer/floating point division on a register, the register(s) being performed on need to actually be <code>initialized</code>. I'm curious to what the proper assembler directive is to do this. Do I simply provide an address by something like:</p>
  
  <p><code>mov ecx, 0x65F ;0x65F represents an address for ecx to point to</code>.</p>
  
  <p>And then promptly (later in code) do something like:</p>
  
  <p><code>mov byte [ecx], 0xA ;move the value of 0xA into the contents of ecx, using only a byte's worth of data</code> </p>
  
  <p>Is this the proper way to perform such an operation? If not, what is?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Ok, so what I'm trying to do is basically multiply two values and print them to the screen.
  The code is as follows, and for some reason every time I try to divide <code>edx</code> I get either a segmentation fault or a floating point arithmatic exception. Could someone explain to me what it is that I'm doing wrong?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>section .data
      counter: db 0xA                         ;store value 10 in 'counter', while allocating only one byte. This will be used for decrementing purposes
  section .bss
      valueToPrint: resb 4                    ;alloc 4 bytes of data in 'valueToPrint'
  
  section .text
  
  global _start
  
  _print_char:                    
      add eax, '0'                ;convert to ascii
      mov [valueToPrint], eax     ;store contents of 'eax' in valueToPrint
      mov eax, 4                  ;syswrite
      mov ebx, 1                  ;stdout
      mov ecx, valueToPrint       ;machine will take whatever value exists in 'ecx' and print
      mov edx, 1                  ;print only a single byte's worth of data
      int 0x80                    ;invoke kernel to perfrom instruction
      ret                         
  
  _convert_values:
      mov edx, 0xA                ;dividing eax by 10, which will lower its tens place
      div edx                     ;(**Program crash here**)do division: remainder SHOULD be stored in edx
      mov byte [edx], 0x0         ;zero out edx       
      call _print_char            ;do printing for latest character
      dec byte [counter]          ;decrement counter
      mov dword [eax], counter    ;store counter in eax
      jnz _convert_values         ;while eax &gt; 0 continue process
  
  _endl:
      mov eax, '\n'               ;store newline character in eax to be printed
      call _print_char            ;print value
      ret                 
  
  _mul:
      mov eax, 0x2A ;store 42 in eax
      mov edx, 0x2B ;store 43 in edx
      mul edx       ;multiply [eax] * [edx]
      ret
  
  _safe_exit:
      mov eax, 1  ;initiate 'exit' syscall
      mov ebx, 0  ;exit with error code 0
      int 0x80    ;invoke kernel to do its bidding 
  
  _start:
      nop                             ;used to keep gdb from complaining
  
      call _mul                       ;multiply the values
      call _convert_values            ;do hex to ascii conversion
  
      jmp _safe_exit                  ;use jmp as opposed to call since it technically doesn't 'ret'
  </code></pre>