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