1

How to write if statements in Pep9 Assembly? I want to write this if statement from C in Pep9 Assembly form.

if ( (0 < weight) && (weight <= 1 ) ) {
    printf("Light Weight\n");
}
else if((1 < weight) && (weight <= 3)){
    printf("Medium Weight\n");
}

But I fail to print the results when the input is more than 1. This is what I have so far:

if:   LDWA weight,s  ;if(0 < weight) 
      CPWA limit11,i
      BRLT msg1 
      LDWA weight,s  ;if(weight <= 1)
      CPWA limit12,i 
      BRGT msg1 
      STRO cost1,d  
   cost1: .ASCII "Low Weight\n\x00"    
   msg1: .END   
 
if:   LDWA weight,s  ;if(1 < weight) 
      CPWA limit21,i 
      BRLT msg2
      LDWA weight,s  ;if(weight <= 3)
      CPWA limit22,i  
      BRGT msg2 
      STRO cost2,d  
   cost2: .ASCII "Medium Weight

The first if statement works fine. But the second one fails to print anything. Can you please point out where the problem is?

Wusion
  • 25
  • 1
  • 8

1 Answers1

1

I don't know PEP8/9 intimately, but here are some thoughts:

You're trying to do an if-then-else-if-then statement.

Pay special attention to how the first if-then flows into the 2nd if-then (via else).

Here you are putting cost1, data, in between the first if and the 2nd if.  The processor doesn't automatically know to skip data in the execution stream (flow of control).  If it were me, I would relocate all the data (strings, etc) to the end, but if you want them inline, then branch around them using an unconditional branch, if needed so the processor is told to skip the strings.

Your .END should probably be the last statement of the code, rather than being in the middle.


If none of that works, then show us all your code, not just snippets.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53