Search code examples
cassemblypdp-11

sub-routines on Assembly


can I do something like this 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 must write jsr and sub-routine but can I do something like this bne sub-routine


Solution

  • In assembly that would usually be translated into 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:
    

    ie. the if statement is converted into a jump that jumps over the body of the if if the controlling expression is not true.