Ad

Bitwise Inverter

write a program that performs a bitwise invertion to a given number

Examples:

invertbits(3) => returns 252 (11111100)

invertbits(255) => returns 0 (00000000)

Code
Diff
  • global invertbits
    
    section .text
    
    ; <--- unsigned invertbits(const int num) --->
    ; rdi=num
    invertbits:
        xor rax, rax        ; EAX <- the result
        not rdi
        mov rax, rdi
        ret
    ; ---------> endof invertbits <---------
    • unsigned char invertbits(unsigned char value)
    • {
    • return value ^ 0xFF;
    • }
    • global invertbits
    • section .text
    • ; <--- unsigned invertbits(const int num) --->
    • ; rdi=num
    • invertbits:
    • xor rax, rax ; EAX <- the result
    • not rdi
    • mov rax, rdi
    • ret
    • ; ---------> endof invertbits <---------