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
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
 
    
     
    
    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
 
    
    main.c
#include <stdio.h> 
#include "concatBytes.h" 
char byte1 = '11101010'; 
char byte2 = '10100001'; 
int main()
{ 
    short result = 0; 
    result = concatBytes(); 
    printf("Result = %hd",result); 
    return 0;
}
concatBytes.h
short concatBytes(void);
concatBytes.c
extern char byte1; 
extern char byte2;
short concatBytes(void)
{
    return(((short)byte1)^((short)byte2));
}
so obviously:
gcc main.c concatBytes.c -o main
main.c:3:14: warning: character constant too long for its type
 char byte1 = '11101010'; 
              ^
main.c:3:14: warning: overflow in implicit constant conversion [-Woverflow]
main.c:4:14: warning: character constant too long for its type
 char byte2 = '10100001'; 
              ^
main.c:4:14: warning: overflow in implicit constant conversion [-Woverflow]
that is bad syntax. so that leads to the question did you mean this:
#include <stdio.h> 
#include "concatBytes.h" 
char byte1[] = "11101010"; 
char byte2[] = "10100001"; 
int main()
{ 
    short result = 0; 
    result = concatBytes(); 
    printf("Result = %hd",result); 
    return 0;
}
or this:
#include <stdio.h> 
#include "concatBytes.h" 
char byte1 = 0xEA; 
char byte2 = 0xA1; 
int main()
{ 
    short result = 0; 
    result = concatBytes(); 
    printf("Result = %hd",result); 
    return 0;
}
assuming the latter:
0000000000400559 <concatBytes>:
  400559:   55                      push   %rbp
  40055a:   48 89 e5                mov    %rsp,%rbp
  40055d:   0f b6 15 d4 0a 20 00    movzbl 0x200ad4(%rip),%edx        # 601038 <byte1>
  400564:   0f b6 05 ce 0a 20 00    movzbl 0x200ace(%rip),%eax        # 601039 <byte2>
  40056b:   31 d0                   xor    %edx,%eax
  40056d:   66 98                   cbtw   
  40056f:   5d                      pop    %rbp
  400570:   c3                      retq   
which gives you a rough idea of the calling convention and then you simply replace the middle of that code with your "concatenate"
If it is a string then you first need to convert each to a byte, then concatenate. You can just as easily figure that one out...
