English 中文(简体)
What is wrong with this RISC-V interpreter code in cornells?
原标题:

Consider:

    addi t0, zero, 3
    addi a6, zero, 3

fast_multiply:
   ADD  a0, zero, zero

next_digit:
   ANDI a1, a6, 1
   SRAI a6, a6, 1

   BEQ  a1, zero, skip
   ADD  a0, a0, t0

skip:
   SLLI t0, t0, 1
   BNE  a6, zero, next_digit
   ADD  t0, zero, a0
   sw a0, 0x0(x0)



    addi t1, zero, 5
    addi a7, zero, 5

fast_multiply2:
   ADD  a2, zero, zero

next_digit2:
   ANDI a3, a7, 1
   SRAI a7, a7, 1

   BEQ  a3, zero, skip
   ADD  a2, a2, t1

skip2:
   SLLI t1, t1, 1
   BNE  a7, zero, next_digit
   ADD  t1, zero, a2
   sw a2, 0x4(x0)

When I try to move onto the next integer, it continues to run.

问题回答

The second copy of fast multiply has a typo in the label.

BEQ  a3, zero, skip     

should be jumping to skip2.

If you can t find the problem by reading the code, you can observe the problem by single step debugging — you can notice the control flow that inside the second look it is jumping back into the first loop.

The same problem for

skip2:
   SLLI t1, t1, 1        
   BNE  a7, zero, next_digit

Should be jumping to next_digit2.

We can also think of this as copy & paste error common to assembly language and due to the use of labels and the fact that labels have to be renamed in order to deconflict them from those in the first copy.  Some assembly languages have a feature called local label to reduce this type of error.





相关问题
List of suspected Malicious patterns

I am doing an anti-virus project by disassembling its code and analyzing it. So I want a list of the Suspected Malicious pattern codes, so I can observe which is suspected and which is not? So I want ...

Prefetch for Intel Core 2 Duo

Has anyone had experience using prefetch instructions for the Core 2 Duo processor? I ve been using the (standard?) prefetch set (prefetchnta, prefetcht1, etc) with success for a series of P4 ...

How are mutex and lock structures implemented?

I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions ...

Installing GNU Assembler in OSX

No matter how hard I google, I can t seem to find a (relatively) easy-to-follow instruction on how to install the GNU Assembler on a mac. I know I can use gcc -c (Apple Clang on a Mac) to assemble .s ...

8086 assembler,INT 16,2

I got stuck at this thing,I want to see if right shift button has been pressed,so I have this assambler code: mov ah,2 int 16h ;calling INT 16,2 - Read Keyboard Flags interrupt mov ah,...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签