.global main            # makes label "main" globally known

        .text                   # Instructions follow
        .align  2               # Align instructions to 4-byte words

main:   movi    r16,0x47        # Load the hexadecimal value 41
                                # to register r16

loop:   mov     r4,r16          # Copy to r4 from r16

        nop                     # (later changed to call hexasc)
        nop                     # (later changed to mov r4,r2)

        movia   r8,putchar      # copy subroutine address to a register
        callr   r8              # call subroutine via register

        addi    r16, r16,1      # Add 1 to register r16
        andi    r16, r16, 0x7f  # mask with 7 bits
        ori     r16, r16, 0x20  # set a bit to avoid control chars

        br      loop            # Branch to loop

        .end                    # The assembler will stop reading here
        foo bar bletch          # comes after .end - ignored

我想,除了 andiori 两条指令在这种情况下的工作方式之外,我什么都能理解。 ori 似乎使向前打印 ASCII 20 位置,但为什么以及如何打印?

最佳答案

andi 和 ori 都是按位运算符:

要查看差异,请考虑“

and $rd, $rs, $rt
or  $rd, $rs, $rt

相对
andi $rt, $rs, immed
ori  $rt, $rs, immed

http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/bitwise.html

关于assembly - andi 和 ori 在这个程序中做什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12032437/

10-13 08:37