Search code examples
assemblymasking

Adding 0x80000000 to register won't work when trying to build a mask


Given the following code:

.section .rodata

input_format:  .string  "%d"
output_format1: .string  ""
output_format2: .string ""

.section .text
.globl  main
    .type main, @function
main:
    pushl   %ebp
    movl    %esp,   %ebp

.loop:
    addl    $-4 ,%esp           # moving down the stack
    pushl   %esp
    pushl   $input_format
    call    scanf               # call scanf to get a number from the user
    addl    $8,%esp
    movl    (%esp),%edx         # get the new number

    movl    $0,%esi             # reseting first mask
    addl    $0x1,%esi           # first mask of 0x1
    movl    $0,%ecx             # reseting second mask
    addl    $0x80000000,%ecx

        // more code in the future

    # return from printf:

    movl    %ebp,%esp
    popl    %ebp
    ret

I'm trying to build a mask in order to identify if a given number is a palindrome. So I want to have to masks, first with all zeros and a "1" bit in the MSB, and the other with all zeros and "1" bit in the LSB, and then run 16 times and compare the result using AND. However, when writing addl $0x80000000,%ecx , the register %ecx won't get the immediate 0x80000000. Why is that ?


Solution

  • What is 0x80000000 + 0x80000000? The result of that is why it doesn't seem to work.

    To set the high bit no matter what, use the bit operations

     orl  $0x80000000, %ecx