2.01 Print a triangle to console
You are asked to develop an 8086 assembly program that reads from console a number N (where 0 < N < 10 ) and prints to console a triangle composed by N rows using “*” chars.
For example, given N = 5 :
N=5
*
**
***
****
*****
N=8
*
**
***
****
*****
******
*******
********
Notes:
• In order to print a “new line” ( the ‘\n’ in C programming Language) you have to print two characters 0x0A ( CR Carriage Return) and 0x0D (LF Line Feed).
• Since through INT21h facility you can get from console only a single char (the ASCII code of the input character is returned), in order to convert it in an integer number (N), you have to perform the subtraction between the input char and the ASCII code of the ‘0’ char. N = ASCII_CODE(input_char) - ASCII_CODE(0).
C SOLUTION
void paint(){
int nrow,i,j;
printf("Insert a number [1,9] :");
scanf("%d", &nrow);
if(nrow==0)return;
if(nrow>9)return paint();
printf("\n");
for(i=0;i<nrow;i++){
for(j=0;j<=i;j++){
putchar('*');
}
putchar('\n');
}
}
2.02 Calculate the sum of both positive and negative elements of an array
You are asked to develop an 8086 assembly program that calculate the sum of both positive and negative elements of a signed integer array.
Both the array and the two result variables (negative_sum_result and positive_sum_result) are stored in memory
2.03 Sort an array
You are asked to develop an 8086 assembly program that performs sorting of a signed integer 10 elements array using bubble-sort algorithm. The array is stored in memory.
C SOLUTION
void bsort(int v[], int n)
{
int i, j,temp;
for(i = 0; i < n - 1; i++)
{
for(j = 0; j < n - 1 - i; j++)
{
if(v[j] > v[j+1])
{
temp = v[j];
v[j] = v[j+1];
v[j+1] = temp;
}
}
}
}
2.04 Print a triangle to console (2)
You are asked to develop an 8086 assembly program that reads from console a number N and prints to console a triangle composed by N rows using “*” chars, as in the following diagram.
For terminal console compatibility reasons, you are asked to check that the maximum number of column is 80
Example:
How many row for the triangle? = 12
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*********************
***********************
Please note that the number of columns at the triangle base is given by the following :
nCol = nRow * 2 - 1;
大家帮帮忙,题目应该不是很难,主要是英语,大家查一下吧。要的很急,会的同学请于11月20号给我,就是周六。发到我邮箱里,honeybunny9048@hotmail.com。最好全做,如果实在不行,编出来哪道就把哪道发到我邮箱里。跪谢!!!
.MODEL small
.STACK
.DATA
string1 db "Insert a number [1,9] : $"
.CODE
.STARTUP
start:
mov dx, offset string1
mov ah, 9
int 21h
mov ah, 1
int 21h
sub al,30h ; we need a number and not a char, look ascii code
xor cx,cx ; clean cx
mov cl,al ; set cycle counter
xor bx,bx ; clean bx
mov bx,1
mov dl,0Dh
mov ah,2
int 21h
mov dl,0Ah
mov ah,2
int 21h
cmp cx,0
je finish
cmp cx,9
jg start
cycle_begin:
push cx
mov cx,bx
cycle_rowprint:
mov dl,'*'
mov ah,2
int 21h
loop cycle_rowprint
mov dl,0Dh
mov ah,2
int 21h
mov dl,0Ah
mov ah,2
int 21h
inc bx
pop cx
loop cycle_begin
finish:
.EXIT &