计算、输出杨辉三角形,并不用那样麻烦。
况且,他的程序,有错的。
数据大于256时,计算就出错了,在他的截图中,已经表现出错误了。
如果把数据限定在 65536 之内,输出的行数,就不能超过 18。
他竟然能弄出 500 行来。
这样的错误程序,也敢传上文库 !
如果不考虑输入、输出的子程序,计算杨辉三角形的程序是很简单的。
如下所示:
MOV CX, X ;取来刚刚输入的数字
CALL CR_LF ;回车换行
M_LOP: ;CX=1~18
LEA SI, tmp1
MOV BX, 0
CALL YangHui ;输出一行
CALL CR_LF
LOOP M_LOP ;循环1~18次
;--------------------------------
EXIT:
MOV AH, 4CH
INT 21H
;=====================================
YangHui: ;计算杨辉三角形
MOV AX, [SI] ;取出数据
ADD AX, BX ;加上《左边数据》
MOV BX, [SI] ;再次取出数据,当做下次的《左边数据》
MOV [SI], AX ;保存和
JZ END_YH ;为零就停止
ADD SI, 2
CALL PRINT_AX ;输出
CALL SPACE
JMP YangHui ;循环
END_YH:
RET
;=====================================
CX=18时,就会输出显示18行。
*** 作过程如下:
-----------------------------------------
YangHui triangel
-----------------------------------------
Please input the output LineNumber [1~18] : 18
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
1 11 55 165 330 462 462 330 165 55 11 1
1 12 66 220 495 792 924 792 495 220 66 12 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1
1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1
1 16 120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820 560 120 16 1
1 17 136 680 2380 6188 12376 19448 24310 24310 19448 12376 6188 2380 680 136 17
1
1 18 153 816 3060 8568 18564 31824 43758 48620 43758 31824 18564 8568 3060 816 1
53 18 1
0000 0 黑色
0001 1 蓝色
0010 2 绿色
0011 3 青色
0100 4 红色
0101 5 品红色
0110 6 棕色
0111 7 白色
1000 8 灰色
1001 9 淡蓝色
1010 10 淡绿色
1011 11 淡青色
1100 12 淡红色
1101 13 淡品色
1110 14 **
DATAS SEGMENT
COLOR DW 02
BKCOLOR DW 15
COLORINFO DB 13,10,'PLEASE INPUT COLOR HEX CODE(0~E):$'
CRLF DB 13,10,'$'
LENINFO DB 13,10,'PLEASE INPUT THE LENGTH:$'
BUFF DB 10,0,10 DUP (0)
POINT DW 200,400,400,200
DW 200,200,300,100
DW 400,200,300,100
DATAS ENDS
STACKS SEGMENT
DW 200 DUP(0)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START: MOV AX,DATAS
MOV DS,AX
MOV AX,0A000H
MOV ES,AX
CALL INPUTCOLOR
MOV AH,9
MOV DX,OFFSET CRLF
INT 21H
CALL INPUTLEN
MOV AX,0012H
INT 10H ;设置64048016图形模式
MOV AL,2
CALL SET_WRITE_MODE
MOV AX,BKCOLOR
CALL CLEAR
MOV CX,4
MOV SI,OFFSET POINT
DDD: PUSH CX
PUSH SI
MOV AX,[SI]
PUSH AX
MOV AX,[SI+2]
PUSH AX
MOV AX,[SI+4]
PUSH AX
MOV AX,[SI+6]
PUSH AX
CALL LINE
POP SI
ADD SI,8
POP CX
LOOP DDD
MOV AH,01H
INT 21H
MOV AX,4C00H
INT 21H
PIXEL:
PUSH BP
PUSH BX
PUSH CX
PUSH DS
MOV BP,SP
MOV AX,80
MOV BX,WORD PTR[BP+12] ;BX<=Y
MUL BX ;(DX:AX)<=80Y
MOV BX,AX ;
MOV AX,WORD PTR[BP+14] ;AX<--X
MOV CL,8 ; | |
DIV CL ;AL<=商(X/8),AH<=余数(X%8) SP-> | |
MOV CL,AH ;CL<=AH | DS |<-BP
MOV AH,0 ; | CX |<-BP+2
ADD BX,AX ;BX(OFFSET)<=80Y+X/8 | BX |<-BP+4
MOV AL,80H ; | BP |<-BP+6
SHR AL,CL ;AL(MASK)<=(80H>>CL) |返回地址|<-BP+8
PUSH AX ; | COLOR |<-BP+10
MOV DX,3CEH ; | Y |<-BP+12
MOV AL,8 ; | X |<-BP+14
OUT DX,AL ; | |
MOV DX,3CFH ; PIXEL堆栈结构
POP AX
OUT DX,AL
MOV AL,ES:[BX]
MOV AX,WORD PTR[BP+10] ;AX<=COLOR
MOV BYTE PTR ES:[BX],AL
POP DS
POP CX
POP BX
POP BP
RET 6
LINE:
PUSH BP
MOV BP,SP
SUB SP,16
MOV WORD PTR[BP-6],0 ;X=0
MOV WORD PTR[BP-8],0 ;Y=0
MOV WORD PTR[BP-14],1 ;INCX=1
MOV WORD PTR[BP-16],1 ;INCY=1
MOV AX,WORD PTR[BP+6] ;AX<=X2
SUB AX,WORD PTR[BP+10] ;AX<=X2-X1
JNC L1 ;IF X2>=X1,JMP L1
NEG AX ;IF X2<X1,DELTA_X=-DELTA_X
MOV WORD PTR[BP-14],-1 ;INCX<=-1
L1: CMP AX,0 ;IF DELTA_X!=0,JMP L11
JNE L11 ;
MOV WORD PTR[BP-14],0 ;INCX<=0
L11: MOV WORD PTR[BP-10],AX ;DELTA_X<=AX SP-> | |
MOV AX,WORD PTR[BP+4] ;AX<=Y2 | INCY |
SUB AX,WORD PTR[BP+8] ;AX<=Y2-Y1 | INCX |<-BP-14
JNC L2 ;IF Y2>=Y1,JMP L2 | DELTA_Y|<-BP-12
NEG AX ;IF Y2<Y1,DELTA_Y=-DELTA_Y | DELTA_X|<-BP-10
MOV WORD PTR[BP-16],-1 ;INCY<=-1 | Y |<-BP-8
L2: CMP AX,0 ;IF DELTA_Y!=0,JMP L22 | X |<-BP-6
JNE L22 ; |DISTANCE|<-BP-4
MOV WORD PTR[BP-16],0 ;INCY<=0 | T |<-BP-2
L22: MOV WORD PTR[BP-12],AX ;DELTA_Y<=AX | BP |<-BP
LP4: MOV AX,WORD PTR[BP-10] ;AX<=DELTA_X |返回地址|<-BP+2
CMP AX,WORD PTR[BP-12] ; | Y2 |<-BP+4
JG LP5 ;DELTA_X>DELTA_Y | X2 |<-BP+6
MOV AX,WORD PTR[BP-12] ; | Y1 |<-BP+8
MOV WORD PTR[BP-4],AX ;DISTANCE<=DELTA_Y | X1 |<-BP+10
JMP LP51 ; | |
LP5: MOV AX,WORD PTR[BP-10] ; LINE堆栈结构
MOV WORD PTR[BP-4],AX ;DISTANCE<=DELTA_X
LP51: INC AX
MOV WORD PTR[BP-2],AX
LP6: PUSH WORD PTR[BP+10]
PUSH WORD PTR[BP+8]
PUSH COLOR
CALL PIXEL
MOV AX,WORD PTR[BP-6] ;AX<=X
ADD AX,WORD PTR[BP-10] ;AX<=X+DELTA_X
MOV WORD PTR[BP-6],AX ;X=X+DELTA_X
MOV AX,WORD PTR[BP-8] ;AX<=Y
ADD AX,WORD PTR[BP-12] ;AX<=Y+DELTA_Y
MOV WORD PTR[BP-8],AX ;Y=Y+DELTA_Y
MOV AX,WORD PTR[BP-6] ;AX<=X
CMP AX,WORD PTR[BP-4]
JLE LP7 ;IF X<=DISTANCE,JMP LP7
MOV AX,WORD PTR[BP-6] ;X>DISTANCE
SUB AX,WORD PTR[BP-4] ;AX<=X-DISTANCE
MOV WORD PTR[BP-6],AX ;X=X-DISTANCE
MOV AX,WORD PTR[BP+10] ;AX<=X1
ADD AX,WORD PTR[BP-14] ;AX<=X1+INCX
MOV WORD PTR[BP+10],AX ;X1=X1+INCX
LP7: MOV AX,WORD PTR[BP-8] ;AX<=Y
CMP AX,WORD PTR[BP-4]
JLE LP8 ;IF Y<=DISTANCE,JMP LP8
MOV AX,WORD PTR[BP-8] ;Y>DISTANCE
SUB AX,WORD PTR[BP-4] ;AX<=Y-DISTANCE
MOV WORD PTR[BP-8],AX ;Y=Y-DISTANCE
MOV AX,WORD PTR[BP+8] ;AX<=Y1
ADD AX,WORD PTR[BP-16] ;AX<=Y1+INCY
MOV WORD PTR[BP+8],AX ;Y1=Y1+INCY
LP8: DEC WORD PTR[BP-2] ;IF T!=0,JMP LP6
JZ LP9
JMP LP6
LP9: MOV SP,BP
POP BP
RET 8
SET_WRITE_MODE:
PUSH AX
MOV DX,3CEH
MOV AL,5
OUT DX,AL
MOV DX,3CFH
POP AX
OUT DX,AL
MOV DX,3CEH
MOV AL,8
OUT DX,AL
MOV DX,3CFH
MOV AL,0FFH
OUT DX,AL
RET
CLEAR:
MOV BX,0
CLR1: MOV ES:[BX],AL
INC BX
CMP BX,80480
JNB CLR2
JMP CLR1
CLR2: RET
INPUTCOLOR:
MOV AH,9
MOV DX,OFFSET COLORINFO
INT 21H
MOV AH,1
INT 21H
CMP AL,30H
JB INPUTCOLOR
CMP AL,39H
JB INPUTOK
CMP AL,61H
JB BIGCHAR
SUB AL,20H
BIGCHAR:CMP AL,'A'
JB INPUTCOLOR
CMP AL,'F'
JNB INPUTCOLOR
INPUTOK:MOV AH,0
MOV [COLOR],AX
RET
INPUTLEN:
MOV AH,9
MOV DX,OFFSET LENINFO
INT 21H
MOV AH,10
MOV DX,OFFSET BUFF
INT 21H
CALL ABC ;AX为长度
CMP AX,50
JA Q1
MOV AX,50;最小50
JMP OK
Q1:
CMP AX,480
JB OK
MOV AX,480
OK:
MOV BX,640
SUB BX,AX
MOV CX,1
SHR BX,CL
MOV SI,OFFSET POINT ;X居中
MOV [SI],BX
MOV BX,480
SUB BX,AX
MOV CX,1;Y居中
SHR BX,CL
MOV CX,480
SUB CX,BX
MOV [SI+2],CX
MOV BX,[SI]
MOV DX,BX;1X
MOV CX,[SI+2];1Y
ADD BX,AX
MOV [SI+4],BX ;2X
MOV [SI+6],CX ;2Y
MOV [SI+8],DX
MOV [SI+10],CX
MOV [SI+16],BX
MOV [SI+18],CX
PUSH AX
PUSH CX
MOV CX,1
SHR AX,CL
POP CX
ADD DX,AX
MOV [SI+12],DX;3X
MOV [SI+20],DX;3X
MOV BX,866;866
POP AX
MUL BX
MOV BX,1000
DIV BX
SUB CX,AX
MOV [SI+14],CX
MOV [SI+22],CX
RET
;POINT DW 200,200,400,200 1P-2P
; DW 200,200,300,100 1P-3P
; DW 400,200,300,100 2P-3P
ABC PROC
MOV CH,0
MOV BX,OFFSET BUFF
MOV CL,[BX+1]
CMP CX,0
JZ ABCD
PUSH CX
ADD BX,2
PUSH BX
L0: SUB [BX],30H
INC BX
LOOP L0
POP BX
MOV AX,0
MOV CH,0
MOV CL,[BX-1]
L111: MOV DL,10
MUL DL
ADD AL,BYTE PTR [BX]
INC BX
LOOP L111
POP CX
ABCD: RET
ABC ENDP
CODES ENDS
END START
以上就是关于谁会改这个用汇编些的杨辉三角全部的内容,包括:谁会改这个用汇编些的杨辉三角、等边三角形的绘制的程序设计、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)