高分悬赏!!!!急求汇编答案!!!!! 100
2.01PrintatriangletoconsoleYouareaskedtodevelopan8086assemblyprogramthatreadsfromcons...
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 & 展开
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 & 展开
1个回答
展开全部
6道题才100分啊?? 就先做4道吧,分少、又是在帮人作弊,没激情啊……
2.01
.model small
.stack 8192
.data
prompt db 'N=$'
.code
main: mov ax,@data
mov ds,ax
assume ds:@data
mov dx,offset prompt
mov ah,9
int 21h
getkey:
mov ah,8 ;dos call getkey w/o echo
int 21h
cmp al,27 ;escape key for quit
je done
mov dl,al ;save to dl for echo
sub al,'0'
jbe getkey
cmp al,9
ja getkey
push ax
mov ah,2 ;echo keypress
int 21h
call crlf
pop ax
cbw
mov si,ax ;save n into si
mov di,1
lp1:
mov cx,di
mov dl,'*'
lp2: mov ah,2
int 21h
loop lp2
call crlf
inc di
cmp di,si
jna lp1
done: mov ah,4ch
int 21h
crlf proc
mov ah,2
mov dl,13 ;cr
int 21h
mov dl,10 ;lf
int 21h
ret
crlf endp
end main
2.02
ARRAYSIZE equ 100
.model small
.stack 8192
.data
negative_sum_result dd 0
positive_sum_result dd 0
array dw ARRAYSIZE dup (?)
.code
main: mov ax,@data
mov ds,ax
mov cx,ARRAYSIZE
cld
lp: lodsw
mov bx,offset positive_sum_result
cmp ax,0
jg pos
mov bx,offset negative_sum_result
pos: add word ptr [bx],ax
adc word ptr [bx+2],0
loop lp
mov ah,4ch
int 21h
end main
2.03
.model small
.stack 8192
.data
array dw 8,3,1,4,6,9,8,0,-1,-3
.code
main: mov ax,@data
mov ds,ax
mov es,ax
assume ds:@data,es:@data
mov ax,10
push ax
mov ax,offset array
push ax
call bsort
add sp,4
done: mov ah,4ch
int 21h
bsort proc near
v equ word ptr [bp+2]
n equ word ptr [bp+4]
mov bp,sp
mov bx,v
mov cx,n
dec cx
xor si,si ;i*2
add cx,cx
lpi: cmp si,cx
jge bs_done
xor di,di ;j*2
lpj: push cx
sub cx,si
cmp di,cx
pop cx
jge lpi9
mov ax,[bx+di] ;v[j]
cmp ax,[bx+di+2] ;>v[j+1]?
jle lpj9
xchg ax,[bx+di+2] ;swap ax,v[j+1], note at this moment ax=v[j]
mov [bx+di],ax ;v[j]:=v[j+1]
lpj9: inc di
inc di
jmp lpj
lpi9: inc si
inc si
jmp lpi
bs_done:
mov sp,bp
ret
bsort endp
end main
2.04
.model small
.stack 8192
.data
prompt db 'How many row for the triangle? = $'
errmsg db 'the number of row should be in range of [1..39].',13,10,10,36
ten db 10
mydata db 3 dup (?)
bksp db 8,' ',8,36
.code
main: mov ax,@data
mov ds,ax
mov es,ax
assume ds:@data,es:@data
input: mov dx,offset prompt
mov ah,9
int 21h
call getnum
jc done ;enter key pressed on an empty line
or ax,ax
jz err
cmp ax,39
jle draw
err: mov dx,offset errmsg
mov ah,9
int 21h
jmp input
draw: mov si,ax ;save n into si
mov di,1
lp1: mov cx,si ;cx=n-row()
sub cx,di ;number of white spaces before the asterisks
jcxz draw2
mov dl,' '
lp11: mov ah,2
int 21h
loop lp11
draw2: mov cx,di
mov dl,'*'
add cx,cx ;cx=row()*2-1, number of asterisks should be printed in the current row
dec cx
lp2: mov ah,2
int 21h
loop lp2
call crlf
inc di
cmp di,si
jna lp1
done: mov ah,4ch
int 21h
crlf proc
mov ah,2
mov dl,13 ;cr
int 21h
mov dl,10 ;lf
int 21h
ret
crlf endp
getnum proc
xor cx,cx
mov di,offset mydata
g_1: mov ah,8
int 21h
cmp al,13
jne g_3
call crlf
jcxz g_2
xor ax,ax
mov si,offset mydata
g_9: mul ten
mov dl,[si]
sub dl,'0'
xor dh,dh
add ax,dx
inc si
loop g_9
clc
ret
g_2: stc
ret
g_3: cmp al,8
jne g_4
jcxz g_1
dec cx
dec di
mov dx,offset bksp ;
mov ah,9
int 21h
jmp g_1
g_4: cmp cx,3
jae g_1
cmp al,'0'
jb g_1
cmp al,'9'
ja g_1
mov dl,al
push ax
mov ah,2
int 21h
pop ax
stosb
inc cx
jmp g_1
getnum endp
end main
2.01
.model small
.stack 8192
.data
prompt db 'N=$'
.code
main: mov ax,@data
mov ds,ax
assume ds:@data
mov dx,offset prompt
mov ah,9
int 21h
getkey:
mov ah,8 ;dos call getkey w/o echo
int 21h
cmp al,27 ;escape key for quit
je done
mov dl,al ;save to dl for echo
sub al,'0'
jbe getkey
cmp al,9
ja getkey
push ax
mov ah,2 ;echo keypress
int 21h
call crlf
pop ax
cbw
mov si,ax ;save n into si
mov di,1
lp1:
mov cx,di
mov dl,'*'
lp2: mov ah,2
int 21h
loop lp2
call crlf
inc di
cmp di,si
jna lp1
done: mov ah,4ch
int 21h
crlf proc
mov ah,2
mov dl,13 ;cr
int 21h
mov dl,10 ;lf
int 21h
ret
crlf endp
end main
2.02
ARRAYSIZE equ 100
.model small
.stack 8192
.data
negative_sum_result dd 0
positive_sum_result dd 0
array dw ARRAYSIZE dup (?)
.code
main: mov ax,@data
mov ds,ax
mov cx,ARRAYSIZE
cld
lp: lodsw
mov bx,offset positive_sum_result
cmp ax,0
jg pos
mov bx,offset negative_sum_result
pos: add word ptr [bx],ax
adc word ptr [bx+2],0
loop lp
mov ah,4ch
int 21h
end main
2.03
.model small
.stack 8192
.data
array dw 8,3,1,4,6,9,8,0,-1,-3
.code
main: mov ax,@data
mov ds,ax
mov es,ax
assume ds:@data,es:@data
mov ax,10
push ax
mov ax,offset array
push ax
call bsort
add sp,4
done: mov ah,4ch
int 21h
bsort proc near
v equ word ptr [bp+2]
n equ word ptr [bp+4]
mov bp,sp
mov bx,v
mov cx,n
dec cx
xor si,si ;i*2
add cx,cx
lpi: cmp si,cx
jge bs_done
xor di,di ;j*2
lpj: push cx
sub cx,si
cmp di,cx
pop cx
jge lpi9
mov ax,[bx+di] ;v[j]
cmp ax,[bx+di+2] ;>v[j+1]?
jle lpj9
xchg ax,[bx+di+2] ;swap ax,v[j+1], note at this moment ax=v[j]
mov [bx+di],ax ;v[j]:=v[j+1]
lpj9: inc di
inc di
jmp lpj
lpi9: inc si
inc si
jmp lpi
bs_done:
mov sp,bp
ret
bsort endp
end main
2.04
.model small
.stack 8192
.data
prompt db 'How many row for the triangle? = $'
errmsg db 'the number of row should be in range of [1..39].',13,10,10,36
ten db 10
mydata db 3 dup (?)
bksp db 8,' ',8,36
.code
main: mov ax,@data
mov ds,ax
mov es,ax
assume ds:@data,es:@data
input: mov dx,offset prompt
mov ah,9
int 21h
call getnum
jc done ;enter key pressed on an empty line
or ax,ax
jz err
cmp ax,39
jle draw
err: mov dx,offset errmsg
mov ah,9
int 21h
jmp input
draw: mov si,ax ;save n into si
mov di,1
lp1: mov cx,si ;cx=n-row()
sub cx,di ;number of white spaces before the asterisks
jcxz draw2
mov dl,' '
lp11: mov ah,2
int 21h
loop lp11
draw2: mov cx,di
mov dl,'*'
add cx,cx ;cx=row()*2-1, number of asterisks should be printed in the current row
dec cx
lp2: mov ah,2
int 21h
loop lp2
call crlf
inc di
cmp di,si
jna lp1
done: mov ah,4ch
int 21h
crlf proc
mov ah,2
mov dl,13 ;cr
int 21h
mov dl,10 ;lf
int 21h
ret
crlf endp
getnum proc
xor cx,cx
mov di,offset mydata
g_1: mov ah,8
int 21h
cmp al,13
jne g_3
call crlf
jcxz g_2
xor ax,ax
mov si,offset mydata
g_9: mul ten
mov dl,[si]
sub dl,'0'
xor dh,dh
add ax,dx
inc si
loop g_9
clc
ret
g_2: stc
ret
g_3: cmp al,8
jne g_4
jcxz g_1
dec cx
dec di
mov dx,offset bksp ;
mov ah,9
int 21h
jmp g_1
g_4: cmp cx,3
jae g_1
cmp al,'0'
jb g_1
cmp al,'9'
ja g_1
mov dl,al
push ax
mov ah,2
int 21h
pop ax
stosb
inc cx
jmp g_1
getnum endp
end main
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询