Not converting any C program; I just know I could do it in C. I have finished my first try at the program. Decided to do two programs instead of just one.

Code:

#include <iostream>
#include <string>
// C++ converted C headers
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
const char startCommentChar=';';
// Change multiple spaces/tabs into a single space.
int main()
{
std::string aLine;
int i;
while(getline(cin, aLine)){
int lineLen = aLine.length();
bool insideSpace=false;
bool insideComment=false;
for(i=0; i < lineLen; i++){
if(insideComment==false && aLine[i] == startCommentChar){
insideComment=true;
cout << aLine[i];
} else if(insideComment==false && isspace(aLine[i])){
if ( insideSpace==false){
insideSpace=true;
cout << ' ';
}
} else {
insideSpace=false;
cout << aLine[i];
}
} // end for loop
cout << endl;
} // end while loop
return 0;
}

Second program

Code:

#include <iostream>
#include <string>
// C++ converted C headers
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
using std::size_t;
const int instruct_start=10;
const int operand_start=18;
const int comment_start=36; // Also used for directive 2nd operand
const char startCommentChar=';';
const char startDirectiveChar='.';
const char startPreProChar='#';
const int indents[]={10,18,36};
int spaceout(int from, int to);
int main()
{
std::string aLine;
int inpos;
int outpos;
while(getline(cin, aLine)){
int lineLen = aLine.length();
int spaceCount=0;
bool insideComment=false;
bool insidePrePro=false;
for(inpos=0; inpos< lineLen; inpos++){
if(inpos==0 && insidePrePro==false && aLine[inpos] == startPreProChar){
insidePrePro=true;
cout << aLine[inpos];
outpos++;
} else if(insidePrePro==false && insideComment==false && aLine[inpos] == startCommentChar){
insideComment=true;
cout << aLine[inpos];
outpos++;
} else if(insidePrePro==false && insideComment==false && isspace(aLine[inpos])){
if (spaceCount == 0) outpos = inpos;
if (spaceCount > 0 && aLine[inpos+1] == startDirectiveChar){
cout << ' ';
} else {
spaceCount++;
cout << ' ';
if (spaceCount < 4){
outpos = spaceout(outpos+1, indents[spaceCount-1]);
}
} // != startDirectiveChar
} else {
cout << aLine[inpos];
outpos++;
}
} // end for loop
cout << endl;
} // end while loop
return 0;
}
int spaceout(int from, int to){
for(int x = from; x < to; x++) cout << ' ';
return to;
}

Last few lines of the input assembly

Code:

#ifdef L_seuclid
; signed euclidean division
; calling: (left / right)
; push left
; ldd right
; jsr _seuclid
; quotient on the stack (left)
; modulus in d
.area .text
.globl _seuclid
left = 6
right = 2
quo_sgn = 1
mod_sgn = 0
_seuclid:
leas -4,s ; 3 local variables
std right,s
clr mod_sgn,s
clr quo_sgn,s
ldd left,s
bge mod_abs
inc mod_sgn,s ; sign(mod) = sign(left)
inc quo_sgn,s
bsr negd ; abs(left) -> D
mod_abs:
pshs b,a ; push abs(left)
ldd right+2,s ; all references shifted by 2
bge quot_abs
dec quo_sgn+2,s ; sign(quot) = sign(left) XOR sign(right)
bsr negd ; abs(right) -> D
quot_abs:
CALL _euclid ; call (unsigned) euclidean division
std right+2,s
puls a,b ; quot -> D
tst quo_sgn,s ; all references no longer shifted
beq quot_done
bsr negd
quot_done:
std left,s ; quot -> left
ldd right,s
tst mod_sgn,s
beq mod_done
bsr negd
mod_done:
leas 4,s ; destroy stack frame
rts
negd: ; self-explanatory !
nega
negb
sbca #0
rts
#endif
#ifdef L_m0
.area .direct
.globl m0,m1,m2,m3
m0: .blkb 1
m1: .blkb 1
m2: .blkb 1
m3: .blkb 1
#endif
#ifdef L_m4
.area .direct
.globl m4,m5,m6,m7
m4: .blkb 1
m5: .blkb 1
m6: .blkb 1
m7: .blkb 1
#endif
#ifdef L_im0
.area .direct
.globl im0,im1,im2,im3
im0: .blkb 1
im1: .blkb 1
im2: .blkb 1
im3: .blkb 1
#endif
#ifdef L_im4
.area .direct
.globl im4,im5,im6,im7
im4: .blkb 1
im5: .blkb 1
im6: .blkb 1
im7: .blkb 1
#endif
#ifdef L_fm0
.area .direct
.globl fm0,fm1,fm2,fm3
fm0: .blkb 1
fm1: .blkb 1
fm2: .blkb 1
fm3: .blkb 1
#endif
#ifdef L_fm4
.area .direct
.globl fm4,fm5,fm6,fm7
fm4: .blkb 1
fm5: .blkb 1
fm6: .blkb 1
fm7: .blkb 1
#endif

Last few lines of the output assembly

Code:

#ifdef L_seuclid
; signed euclidean division
; calling: (left / right)
; push left
; ldd right
; jsr _seuclid
; quotient on the stack (left)
; modulus in d
.area .text
.globl _seuclid
left = 6
right = 2
quo_sgn = 1
mod_sgn = 0
_seuclid:
leas -4,s ; 3 local variables
std right,s
clr mod_sgn,s
clr quo_sgn,s
ldd left,s
bge mod_abs
inc mod_sgn,s ; sign(mod) = sign(left)
inc quo_sgn,s
bsr negd ; abs(left) -> D
mod_abs:
pshs b,a ; push abs(left)
ldd right+2,s ; all references shifted by 2
bge quot_abs
dec quo_sgn+2,s ; sign(quot) = sign(left) XOR sign(right)
bsr negd ; abs(right) -> D
quot_abs:
CALL _euclid ; call (unsigned) euclidean division
std right+2,s
puls a,b ; quot -> D
tst quo_sgn,s ; all references no longer shifted
beq quot_done
bsr negd
quot_done:
std left,s ; quot -> left
ldd right,s
tst mod_sgn,s
beq mod_done
bsr negd
mod_done:
leas 4,s ; destroy stack frame
rts
negd: ; self-explanatory !
nega
negb
sbca #0
rts
#endif
#ifdef L_m0
.area .direct
.globl m0,m1,m2,m3
m0: .blkb 1
m1: .blkb 1
m2: .blkb 1
m3: .blkb 1
#endif
#ifdef L_m4
.area .direct
.globl m4,m5,m6,m7
m4: .blkb 1
m5: .blkb 1
m6: .blkb 1
m7: .blkb 1
#endif
#ifdef L_im0
.area .direct
.globl im0,im1,im2,im3
im0: .blkb 1
im1: .blkb 1
im2: .blkb 1
im3: .blkb 1
#endif
#ifdef L_im4
.area .direct
.globl im4,im5,im6,im7
im4: .blkb 1
im5: .blkb 1
im6: .blkb 1
im7: .blkb 1
#endif
#ifdef L_fm0
.area .direct
.globl fm0,fm1,fm2,fm3
fm0: .blkb 1
fm1: .blkb 1
fm2: .blkb 1
fm3: .blkb 1
#endif
#ifdef L_fm4
.area .direct
.globl fm4,fm5,fm6,fm7
fm4: .blkb 1
fm5: .blkb 1
fm6: .blkb 1
fm7: .blkb 1
#endif

Tim S.