Subprogrammes at the Assembly

can I do something similar on Assembly bne jsr swap , if not, how can I solve this problem from C, thanks in advance

 if(start!=pivot_index){ swap(board,start,pivot_index); } 

I was taught that I should write jsr and sub-routine , but can I do something like this bne sub-routine

+4
source share
3 answers

In the assembly, which will usually translate to something like this (pseudo-assembly):

 load [start] compare [pivot_index] branch-if-equal label1 push [pivot_index] push [start] push [board] call swap add-stack-pointer 12 label1: 

i.e., the if converted to a jump that jumps over the if body if control expression is not true.

+4
source

Of course you can do it. On x86 you will need two branches:

  # assume EAX = start, EBX = pivot_index cmp eax, ebx beq .SkipSwap call swap .SkipSwap: 

For ARM build, this is simpler because you can use a conditional branch:

  # assume r0 = start, r1 = pivot_index cmp r0, r1 blne swap 
+2
source

No, you cannot do bne subroutine instead of jsr subroutine because jsr means "return to jump".

The difference between this and conditional branch instructions is that jsr pushes the return address jsr stack, so the routine knows where to return. If you just go to the subroutine with bne , the return address is not saved, so the subroutine does not know where to return when it is done.

The answer in the cafe shows you the typical way you would handle this, you just need to translate it into PDP-11 operations.

0
source

Source: https://habr.com/ru/post/1310650/


All Articles