汇编程序设计,高手帮忙!!!!
先对数组排序(冒泡),如从小到大,则分别输出数组的第一个和最后一个元素就是最小值和最大值
调试已通过,-100显示65436
data segment
mes1 db 'the max:$'
mes2 db 'the min:$'
a dw -1,2,100,-100,99,120
data ends
code segment
main proc far
assume cs:code,ds:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov cx,6
dec cx
loop1:
mov di,cx
mov bx,0
loop2:
mov ax,a[bx]
cmp a[bx+2],ax
jge cotinue
xchg ax,a[bx+2]
mov a[bx],ax
cotinue:
add bx,2
loop loop2
mov cx,di
loop loop1
mov dx,offset mes1
mov ah,09h
int 21h
call crlf
mov bx,a[10]
call bini
call crlf
mov dx,offset mes2
mov ah,09h
int 21h
call crlf
mov bx,a[0]
call bini
ret
main endp
bini proc near
mov cx,10000d
call bin
mov cx,1000d
call bin
mov cx,100d
call bin
mov cx,10d
call bin
mov cx,1d
call bin
ret
bini endp
bin proc near
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,02h
int 21h
ret
bin endp
crlf proc near
mov dl,0ah
mov ah,02h
int 21h
mov dl,0dh
mov ah,02h
int 21
ret
crlf endp
code ends
end start
你的这个程序是不是错了?应该有个edi的地址吧?怎么两个都是esi呢?mov cx,20
lea si,buffer1
lea di,buffer2
rep movsw 的程序,是把buffer1里的数据安字传送到buffer2里,传20个次(如果20是10进制的话,)
rep先执行
rep第一次执行时判断cx是否为0,为0执行下面的指令,不为0时,cx减一,并执行后面的movsw指令,movsw就是传送数据。
.386
.STACK 100
.DATA
COLOR DW 02
BKCOLOR DW 15
RADIUS DW 45
;画点宏
MPIXEL MACRO X,Y,COLOR
PUSH X
PUSH Y
PUSH COLOR
CALL PIXEL
ENDM
;画线宏
MLINE MACRO X1,Y1,X2,Y2
PUSH X1
PUSH Y1
PUSH X2
PUSH Y2
CALL LINE
ENDM
;画矩形宏
MRECTANGLE MACRO X1,Y1,X2,Y2
MLINE X1,Y1,X1,Y2
MLINE X1,Y1,X2,Y1
MLINE X2,Y1,X2,Y2
MLINE X1,Y2,X2,Y2
ENDM
;画圆宏
MCIRCLE MACRO X,Y,R
PUSH X
PUSH Y
PUSH R
CALL CIRCLE
ENDM
.CODE
MAIN PROC FAR
START: MOV AX,@DATA
MOV DS,AX
MOV AX,0A000H
MOV ES,AX
MOV AX,0012H
INT 10H ;设置640*480*16图形模式
MOV AL,2
CALL SET_WRITE_MODE ;将写模式设为写模式2
MOV AX,BKCOLOR
CALL CLEAR ;将背景清成白色
MLINE 100,100,150,150
MLINE 300,100,250,150
MLINE 100,300,150,250 ;采用宏
PUSH 300
PUSH 300
PUSH 250
PUSH 250
CALL LINE ;直接调用画线函数
MRECTANGLE 100,100,300,300
MRECTANGLE 150,150,250,250
MCIRCLE 200,200,RADIUS
MOV AH,01H
INT 21H
MOV AX,4C00H
INT 21H
MAIN ENDP
;******************************************
;640*480*16模式下的画点函数
;******************************************
PIXEL PROC
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)<=80*Y
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)<=80*Y+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
PIXEL ENDP
;******************************************
;Bresenham算法实现的画线函数
;******************************************
LINE PROC NEAR
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
LINE ENDP
;***************************************
;Bresenham算法实现的画圆函数
;***************************************
CIRCLE PROC NEAR
PUSH BP
MOV BP,SP
SUB SP,6
MOV WORD PTR[BP-2],0 ;X<=0 | |
MOV AX,WORD PTR[BP+4] ; | |
MOV WORD PTR[BP-4],AX ;Y<=R SP-> | |
MOV AX,-2 ; | P |<-BP-6
IMUL WORD PTR[BP+4] ;AX<=RADIUS*(-2) | Y |<-BP-4
ADD AX,3 ;AX<=3-2*RADIUS | X |<-BP-2
MOV WORD PTR[BP-6],AX ;P=3-2*RADIUS | BP |<-BP
C0: MOV AX,WORD PTR[BP-2] ;AX<=X |返回地址|<-BP+2
CMP AX,WORD PTR[BP-4] ;IF X<Y,JMP C00 | RADIUS |<-BP+4
JL C00 ; | YC |<-BP+6
JMP C3 ; | XC |<-BP+8
C00: PUSH WORD PTR[BP+8] ; CIRCLE堆栈结构
PUSH WORD PTR[BP+6] ;
PUSH WORD PTR[BP-2]
PUSH WORD PTR[BP-4]
CALL CIRCLE_POINT
CMP WORD PTR[BP-6],0
JGE C1
MOV AX,4
MUL WORD PTR[BP-2]
ADD AX,6
ADD AX,WORD PTR[BP-6]
MOV WORD PTR[BP-6],AX
JMP C2
C1: MOV AX,WORD PTR[BP-2]
SUB AX,WORD PTR[BP-4]
MOV BX,4
IMUL BX
ADD AX,10
ADD AX,WORD PTR[BP-6]
MOV WORD PTR[BP-6],AX
DEC WORD PTR[BP-4]
C2: INC WORD PTR[BP-2]
JMP C0
C3: MOV AX,WORD PTR[BP-2]
CMP AX,WORD PTR[BP-4]
JNE C4
PUSH WORD PTR[BP+8]
PUSH WORD PTR[BP+6]
PUSH WORD PTR[BP-2]
PUSH WORD PTR[BP-4]
CALL CIRCLE_POINT
C4: MOV SP,BP
POP BP
RET 6
CIRCLE ENDP
CIRCLE_POINT PROC NEAR
PUSH BP
MOV BP,SP
SUB SP,16
MOV AX,WORD PTR[BP+10] ;
ADD AX,WORD PTR[BP+6] ;
MOV WORD PTR[BP-2],AX ;XC+X
MOV AX,WORD PTR[BP+10] ;
SUB AX,WORD PTR[BP+6] ;
MOV WORD PTR[BP-4],AX ;XC-X
MOV AX,WORD PTR[BP+10] ; | |
ADD AX,WORD PTR[BP+4] ; | |
MOV WORD PTR[BP-6],AX ;XC+Y | |
MOV AX,WORD PTR[BP+10] ; SP-> | |
SUB AX,WORD PTR[BP+4] ; | YC-Y |<-BP-16
MOV WORD PTR[BP-8],AX ;XC-Y | YC+Y |<-BP-14
MOV AX,WORD PTR[BP+8] ; | YC-X |<-BP-12
ADD AX,WORD PTR[BP+6] ; | YC+X |<-BP-10
MOV WORD PTR[BP-10],AX ;YC+X | XC-Y |<-BP-8
MOV AX,WORD PTR[BP+8] ; | XC+Y |<-BP-6
SUB AX,WORD PTR[BP+6] ; | XC-X |<-BP-4
MOV WORD PTR[BP-12],AX ;YC-X | XC+X |<-BP-2
MOV AX,WORD PTR[BP+8] ; | BP |<-BP
ADD AX,WORD PTR[BP+4] ; |返回地址|<-BP+2
MOV WORD PTR[BP-14],AX ;YC+Y | Y |<-BP+4
MOV AX,WORD PTR[BP+8] ; | X |<-BP+6
SUB AX,WORD PTR[BP+4] ; | YC |<-BP+8
MOV WORD PTR[BP-16],AX ;YC-Y | XC |<-BP+10
PUSH WORD PTR[BP-2] ; | |
PUSH WORD PTR[BP-14] ; CIRCLE_POINT堆栈结构
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-4]
PUSH WORD PTR[BP-14]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-2]
PUSH WORD PTR[BP-16]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-4]
PUSH WORD PTR[BP-16]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-6]
PUSH WORD PTR[BP-10]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-8]
PUSH WORD PTR[BP-10]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-6]
PUSH WORD PTR[BP-12]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-8]
PUSH WORD PTR[BP-12]
PUSH COLOR
CALL PIXEL
MOV SP,BP
POP BP
RET 8
CIRCLE_POINT ENDP
;********************************
;清屏函数
;********************************
CLEAR PROC NEAR
MOV BX,0
CLR1: MOV ES:[BX],AL
INC BX
CMP BX,80*480
JNB CLR2
JMP CLR1
CLR2: RET
CLEAR ENDP
;********************************
;设置写模式的函数
;********************************
SET_WRITE_MODE PROC NEAR
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
SET_WRITE_MODE ENDP
END START
连画矩形的都有了
画矩形宏
MRECTANGLE MACRO X1,Y1,X2,Y2
MLINE X1,Y1,X1,Y2
MLINE X1,Y1,X2,Y1
MLINE X2,Y1,X2,Y2
MLINE X1,Y2,X2,Y2
ENDM
;画圆宏
MCIRCLE MACRO X,Y,R
PUSH X
PUSH Y
PUSH R
CALL CIRCLE
ENDM
上面没一个是用的汇编。。。。
汇编画图函数
http://download.csdn.net/source/282149
答:1(1)ADD VAR1,VAR2---两个操作数不能同时为内存单元(2)SUB AL,VAR1---第2个操作数为字单元,不匹配(3)JMP LAB[SI]---标号不能进行变址寻址(4)JNZ VAR1---不能转到变量,只能转到标号(5)JMP NEAR LAB---near 多余2(1)MOV BP,AL---传送的类型不匹配(2)MOV WORD_OP[BX+4*3]...
答:LS第10题、第12题回答错误。1.唯一代表存储空间中每个字节单元的地址是: 物理地址。2.JNC指令转移的测试条件是: 进位标志位复位,即CF=0(源操作数不小于目的操作数)。3.将端口地址为30H中的数据传送到CPU中的指令是: IN AL,30H。4.8086微处理系统中最多有 1024 个端口地址。5.判断无...
答:任意写即可!存放N个有符号或无符号,或只是其中一种情况!N个无符号的相应程序:ORG 0300H AX DATA 20H DX DATA 21H BUF DATA 22H MOV R2,#N MOV R0,#BUF MOV AX,#FFH LOOP1:MOV A,@R0 CJNE A,AX,NEXT1 比较最小部分;NEXT1:JNC NEXT2 MOV AX,A NEXT2:INC R0 DJNZ R2,LOOP...
答:汇编程序中有三类命令:指令 :就一些有实际效果的指令 jr 汇编指示:.text .global main等 宏指令:li mkdir tmp cd tmp vi first.s i /* first.s*/ .text .global main .ent main mian: nop li $v0, 8 jr $ ra .end mian :wq gcc -g -o first first.s ./first echo $?//...
答:五、程序设计题(2道小题,共20分)1、以下5个小题,请分别用一条MASM语句完成其要求。(1)将45H,0F000H,89H存放在变量XYZ的存储单元中。XYZ DB 45H,0F000H,89H (2)预留100个字节单元的存储空间,用变量名BUFFER表示 BUFFER DB 100 DUP(?)(3)将字符串“How are you !
答:2、若在上述设计的指令字中设置一寻址特征位X,且X = 1表示某个寄存器作基址寄存器,画出指令格式。试问基址寻址可否访问主存的任一单元,为什么,如不能,提出一种方案,使其可访问主存的任一位置:解答:上述指令格式中增设一寻址特征位,且X = 1表示某个寄存器作基址寄存器RB。其指令格式为731318...
答:双击可执行程序RQSZ.exe,在出现的提示信息中输入大写字母“D”,可 显示系统当前日期;输入大写字母“T”,可显示系统当前时间;输入大写字母“Q”,可结束程序。STACK SEGMENT STACK DW 200 DUP (?)STACK ENDS DATA SEGMENT SPACE DB 1000 DUP (' ')PATTERN DB 6 DUP (' '),0C9H,26 DUP (0...
答:大致看了下,这个不只是1不1的问题了。。算法太过理想化。 既然你的数是用户输入的,那么几位数是事先未知的,你怎能对齐的算?而且是以0d回车结尾的。你所谓的对齐是不对齐的,你要正确的结果只能是让用户这么输入00012+00013。那你的程序就没意义了。其实你完全可以把输入的字符串转换成数字,...
答:2009-10-23 汇编语言一道题 11 2010-01-03 汇编语言的一道题 3 2009-04-26 汇编语言习题 20 2010-10-17 汇编语言的一题!!急!! 1 2010-07-13 汇编语言的一道题 谢谢啦 1 2009-04-20 汇编语言简单习题 18 2015-02-03 关于汇编语言的一道题!急! 2009-05-13 汇编语言习题答案 20 更多...
答:汇编语言程序设计步骤:1、分析问题,抽象出描述问题的数据模型 2、确定问题的算法思想 3、画出流程图或结构图 4、分配存储器和工作单元(寄存器)5、逐条编写程序 6、静态检查,上机调试 例:编程查找考生的最高分,假设所有考生分数已存入计算机内存。7、分析问题 根据条件、特点、规律 →数学模型 本...