I have been working on converting this C/C++ Program as an assignment for my x86 assembly class, and for the love of anything good I can't figure out what is wrong. It doesn't have a problem when assembling or linking, but when I run it, it gives me: CS:0576 IP: Of19 OP:65 63 69 66 79. I would appreciate any and all help. Thank you very much for your time.

C/C++ Program:

int main ()
{
// DATA SEGMENT
char ch1 = 'A', ch2 = 'Z', ch3;
int num1 = 10, num2 = 20, num3, largest;
char name1[10] = "CMPSC 241 Class";
int numbers[5] = {0};
// CODE SEGMENT
cout << name1 << ‘\n’;
if ( num1 > num2 ) // Conditional Jump Instruction
largest = num1;
else
largest = num2;
for ( num1 = 0; num1 < 5; num1++ ) { // Fixed Duration Loop
numbers[num1] = num2 + 1;
num2--;
}
num1 = 0;
num2 = 10;
num3 = 0; // Variable Duration Loop
while ( num1 <= num2 ) { // Conditional Jump Instruction
num3++;
num1++;
} // Unconditional Jump Instruction
return 0; // Normal Program Termination
}

My assembly code:

COMMENT †
Douglas Martin
MCMPSC-241 2483
2/24/2010
This program was created by converting C++ code into assembly.
†

.MODEL SMALL
.STACK 100

  CR EQU 13		;symbolic constant
  LF EQU 10		;symbolic constant
  
.DATA
  name1 db 'CMPSC 241 Class'
  numbers dw 5 DUP (0)
  ch1 db 'A', CR, LF, '$'
  ch2 db 'Z', CR, LF, '$'
  ch3 db ?
  num1 dw 10
  num2 dw 20
  num3 dw ?
  largest dw ?
 
.CODE
Main PROC

  mov ax, @data
  mov ds, ax		;set DS to point to the data segment

  lea dx, name1
  mov ah, 9h
  int 21h
  
  mov bx, num1
  cmp bx, num2
  jg else1			; conditional jump
  mov cx, largest
  mov cx, num1
  mov largest, cx
  
  else1: 
  mov cx, num2
  mov largest, cx

  mov si, num1		;fixed duration loop
  mov numbers[si], dx
  mov dx, num2
  inc dx
  
  mov num1, 0
  mov num2, 10
  mov num3, 0		;variable duration loop
  mov cx, num1
  cmp cx, num2
  jle while1		;conditional jump instruction

  while1:
  inc num3
  inc num1
  
  RET 0				;normal program termination 
Main ENDP
END	Main	;end program

EDIT: I am having issues with a for loop. 46-52. I took out the for loop work I had because it was giving me all kinds of errors.
UPDATED CODE:

COMMENT †
Douglas Martin
MCMPSC-241 2483
2/24/2010
This program was created by converting C++ code into assembly.
†

.MODEL SMALL
.STACK 100

  CR EQU 13		;symbolic constant
  LF EQU 10		;symbolic constant
  
.DATA
  name1 db 'CMPSC 241 Class'
  numbers dw 5 DUP (0)
  ch1 db 'A', CR, LF, '$'
  ch2 db 'Z', CR, LF, '$'
  ch3 db ?
  num1 dw 10
  num2 dw 20
  num3 dw ?
  largest dw ?
   
.CODE
Main PROC

  mov ax, @data
  mov ds, ax		;set DS to point to the data segment

  lea dx, name1
  mov ah, 9h
  int 21h
  
  mov bx, num1
  cmp bx, num2
  jg else1			; conditional jump
  mov cx, largest
  mov cx, num1
  mov largest, cx
  
  else1: 
  mov cx, num2
  mov largest, cx

  mov cx, 0
  again:
  mov si, num1		;fixed duration loop
  mov numbers[si], dx
  mov dx, num2
  inc dx
  loop again
  
  mov num1, 0
  mov num2, 10
  mov num3, 0		;variable duration loop
  mov cx, num1
  cmp cx, num2
  jle while1		;conditional jump instruction

  while1:
  inc num3
  inc num1
  
  RET 0				;normal program termination 
Main ENDP
END	Main	;end program

Your memory model is small, so you are generating an .EXE
yet you are using a RET to terminate.
MS-DOS does not push a NULL-WORD for .EXE programs.
You define main: as a subroutine, who is calling you.
I believe RET 0 does not return a value it just pops the
return-address into IP and adds +0 to SP.

Change:

.code
main PROC

to

.code
main:

END main ; defines main as entry point

To terminate use:

mov ax, 4c00h ; AL=00 Normal termination
int 21h

MAIN would have been called by a library routine, as you could
see when you looked at your compilers source listing.

.CODE
.code
Main:
mov ax, @data
mov ds, ax ;set DS to point to the data segment
lea dx, name1
mov ah, 9h
int 21h
mov bx, num1
cmp bx, num2
jg else1 ; conditional jump
mov cx, largest
mov cx, num1
mov largest, cx
else1:
mov cx, num2
mov largest, cx
mov cx, 0
again:
mov si, num1 ;fixed duration loop
mov numbers[si], dx
mov dx, num2
inc dx
loop again
mov num1, 0
mov num2, 10
mov num3, 0 ;variable duration loop
mov cx, num1
cmp cx, num2
jle while1 ;conditional jump instruction
while1:
inc num3
inc num1
MOV AH, 4ch
MOV AL, 0  ;normal program termination
INT 21h 
END Main
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.