Search code examples
assemblyx86concatenationbytebit-shift

concatenate two bytes char byte1 and char byte2 into a single short


I want to concatenate two bytes char byte1 and char byte2 into a single short in Assembly.

How can I do it? Using shifts?

I'm working with IA32


Solution

  • I just solved the problem and did this in case somebody has the same problem:

    concatBytes.s :

     .section .data
    
    .global byte1
    .global byte2
    
    .section .text
    .global concatBytes
    
    
    concatBytes:
    
    #prologue 
        pushl %ebp 
        movl %esp, %ebp
        
        pushl %ebx
        
    #body of the function
    
        movl $0, %eax
        movb byte1, %al
        movb byte2, %ah
        
    
        
    #epilogue
    
        popl %ebx
        
        movl %ebp, %esp
        popl %ebp
        ret