jamespierre
02-04-08, 10:32 AM
I am brand new to assembly, and i have just learned how to add two numbers. However I need to add eight numbers, and I just dont know how. here is my trial code
short int num1 = 0x1;
short int num2 = 0x0;
short int num3 = 0x1;
short int num4 = 0x3;
short int num5 = 0x6;
short int num6 = 0x6;
short int num7 = 0x5;
short int num8 = 0x4;
short int ans1 = 0;
__asm {
// | | |
mov ax,num1 ;get first num to add
mov ax,num2 ;get second num to add
mov ax,num3 ;get third num to add
mov ax,num4 ;get fourth num to add
mov ax,num5 ;get fifth num to add
mov ax,num6 ;get sixth num to add
mov ax,num7 ;get seventh num to add
mov ax,num8 ;get eigth num to add
add ax,num2 ;form sum
add ax,num3 ;form sum
add ax,num4 ;form sum
add ax,num5 ;form sum
add ax,num6 ;form sum
add ax,num7 ;form sum
add ax,num8 ;form sum
mov ans1,ax ;store result
}
short int num1 = 0x1;
short int num2 = 0x0;
short int num3 = 0x1;
short int num4 = 0x3;
short int num5 = 0x6;
short int num6 = 0x6;
short int num7 = 0x5;
short int num8 = 0x4;
short int ans1 = 0;
__asm {
// | | |
mov ax,num1 ;get first num to add
mov ax,num2 ;get second num to add
mov ax,num3 ;get third num to add
mov ax,num4 ;get fourth num to add
mov ax,num5 ;get fifth num to add
mov ax,num6 ;get sixth num to add
mov ax,num7 ;get seventh num to add
mov ax,num8 ;get eigth num to add
add ax,num2 ;form sum
add ax,num3 ;form sum
add ax,num4 ;form sum
add ax,num5 ;form sum
add ax,num6 ;form sum
add ax,num7 ;form sum
add ax,num8 ;form sum
mov ans1,ax ;store result
}