Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

Bitwise logical NOT does NOT work!!

Anyhow, I have this Assembly assignment in which I have to count the number of binary 0's in a given hex value. It shows us how to count the 1's. I figured I'd try the NOT operator. It mentions the NOT operator in the InstructionSetReference.PDF, but it doesn't show us how to use it anywhere. I've tried everything I can think of, but all it does is return errors upon compilation with the Altera Monitor Program. When I try it like NOT r2 It gives this error: Error: unrecognised instruction not Compilation stopped. So, what's the deal with this? I go online, and everywhere they talk about the NOT instruction, that's how you use it. Perhaps some of you are familiar with this assignment. Here's the primary code: You see, in part 3, we have to count the 0's instead of the 1's. .text .global _start _start: ldw r2, NUM(r0) /* Loading hex value from the .word directive. I will use that hex number''s binary equivalent. */ mov r5, r0 /* Register is the counter, and increments by one, leaving the last incremented value to be the max number of consequtive 1''s. */ LOOP: beq r2, r0, END /* This loops until r2 no longer contains 1''s in its binary value. */ srli r3, r2, 0x1 /* Shifts binary value of r2 to the right and stores that shifted value into r3 */ and r2, r2, r3 /* ANDing the binary of r2 with the shifted binary of r3 so that all 1''s now ANDed with 0''s turn to 0, and then overwriting r2 with the new binary result */ addi r5, r5, 1 /* Incrementing counter by 1. */ br LOOP /* Relooping this until there are no more 1''s in the binary value of r2. */ END: br END NUM: .word 0x3fabedef /* This is the value who''s binary value will be assessed for max number of consecutive 1''s. */ NOTE: Sorry about how the message all compacted together. I can't seem to figure out how to make it space out properly in this message. It's like this doesn't honor any new lines

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Assuming you are programming the Altera NIOS II processor (you never say, but these are the opcodes you are using...), there is no NOT instruction.

    However, it can be synthesized in a number of ways, the simplest using the NOR instruction with the source register duplicated.

    
       nor  r5,r5,r5  ; ones complement of value in r5
       nor  r3,r4,r4  ; ones complement of value in r4 to r3
    

    BTW here is your code. Put it in a CODE (#) block when you post it.

    
            .text
            .global _start
    _start: ldw     r2, NUM(r0)   /* Loading hex  value from the .word directive. I will use that hex number''s binary  equivalent. */
            mov     r5, r0        /* Register is the counter, and  increments by one, leaving the last incremented value to be the max  number of consequtive 1''s. */
    LOOP:   beq     r2, r0, END   /* This  loops until r2 no longer contains 1''s in its binary value. */
            srli    r3, r2, 0x1   /* Shifts binary value of r2 to the right and stores that  shifted value into r3 */     
            and     r2, r2, r3    /* ANDing the binary of  r2 with the shifted binary of r3 so that all 1''s now ANDed with 0''s  turn to 0, and then overwriting r2 with the new binary result */      
            addi    r5, r5, 1     /* Incrementing counter by 1. */    
            br      LOOP          /* Relooping this until there are no more 1''s in the binary value  of r2. */
    END:    br      END
    NUM:    .word   0x3fabedef    /* This  is the value who''s binary value will be assessed for max number of  consecutive 1''s. */