0

PLEASE somebody help me
I have QUESTIONS about pep/8
and 4 hours left to figure it out

1. in C++, global variable CHAR word[32] = "Backward"; is common
but how do i initialize it in pep/8 ??
I need to write a simple program to flip it backward using stack pointers
and the char array need to be initialized before the main()

2. this is a favor to ask, at the same time I'm also debugging myself
can some1 check this assembly code translated from C++ for me??
I can not find the bug,and the output windows keep showing
"Invalid DECI input"
C++ code

#include<iostream>
using namespace std;

int times(int par, int mcand)
{ if(mpr==0) return 0;
  else if(mpr%2==1) return times(mpr/2, mcand*2)+mcand;
  else return times(mpr/2, mcand*2);
}
int main()
{ int n,m;
  cin>>n>>m;
  cout<<"Product: "<<time(n,m)<<endl;
  return 0;
}

Assembly code

BR      main
;times
mpr:     .EQUATE 0
mcand:   .EQUATE 2
temp:    .EQUATE 4
retVal:  .EQUATE 8
times:   SUBSP   10,i
         LDA     mpr,s
if:      BREQ    then
         STA     temp,s
         LDA     temp,s
         ANDA    1,i
         BRGT    elseif
         BR      else
then:    LDA     0,i
         STA     retVal,s
         RET6
elseif:  LDA     mpr,s
         STA     temp,s
         LDA     temp,s
         ASRA    
         STA     -10,s
         LDA     mcand,s
         STA     temp,s
         LDA     temp,s
         ASLA
         STA     -8,s
         CALL    times
         LDA     -2,s
         STA     retVal,s
         LDA     retVal,s
         ADDA    mcand,s
         RET6
else:    LDA     mpr,s
         STA     temp,s
         LDA     temp,s
         ASRA    
         STA     -10,s
         LDA     mcand,s
         STA     temp,s
         LDA     temp,s
         ASLA
         STA     -8,s
         CALL    times
         LDA     -2,s
         STA     retVal,s
         RET6
;main    
n:       .EQUATE 0
m:       .EQUATE 2
main:    SUBSP   4,i
         DECI    n,s
         DECI    m,s
         LDA     n,s
         STA     -10,s
         LDA     m,s
         STA     -8,s
         CALL    times
         ADDSP   4,i
         STRO    msg,d
         DECO    -2,s
         STOP
msg:     .ASCII  "Product: \x00"
         .END

Edited by bigwhiteegg: n/a

1
Contributor
1
Reply
5
Views
6 Years
Discussion Span
Last Post by bigwhiteegg
0

one more question!!
I have a global variable int list[16]
how do I replace list[n] with a int temp??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.