汇编语言实验三--算术运算与代码转换程序设计.docx
文本预览下载声明
3.3 实验三 算术运算与代码转换程序设计一、实验目的 1)掌握算术运算程序的设计方法。2)掌握代码转换程序的设计方法。 3)进一步掌握各种程序结构。 4)熟练掌握和使用用DEBUG调试程序。 二、实验内容1)编制两个多字节整数加法和减法程序,并将结果按十六进制形式显示在屏幕上。data segment a db 22h,22h,22h,22h,22h,22h,22h,22hb db 11h,11h,11h,11h,11h,11h,11hlenb equ $-blen2 equ (b-a)*2res db len2 dup(?),$data ends stack1 segment stack dw 20h dup(?)stack1 ends code segment assume cs:code,ds:data,ss:stack1start:mov ax,data mov ds,ax mov si,0 clc ;清除进位标志位,置cf等于0mov cx,lenb lop1:mov al,a[si] ;低位相加adc al,b[si]mov a[si],al inc si loop lop1 adc byte ptr a[si],0 ;加进位mov si,0 add si,lenb mov di,0 mov cx,lenb+1lop2:push cx mov al,a[si]mov bl,al mov cl,4shr bl,cl cmp bl,0ah jb next1 ;小于等于则跳转add bl,07h next1:add bl,30h mov res[di],bl inc di mov bl,al and bl,0fh cmp bl,0ah jb next2 add bl,07h next2:add bl,30hmov res[di],bl inc di dec si pop cx loop lop2 mov ah,09h mov dx,offset res int 21h mov ah,4ch int 21hcode ends end start5)编写一通用过程用来将十进制数(从键盘输入)转换为P(从键盘输入)进制数。data segment string1 db input your m=,$string2 db input your p=,$re db 20h dup(0)data endsstack1 segment stack dw 30h dup(0)stack1 endscode segment assume cs:code,ds:data,ss:stack1 start:mov ax,data mov ds,ax mov dx,offset string1mov ah,09h ;显示字符串int 21hmov ah,1int 21hand ax,000fh ;等价于mov ah,0mov dl,10mul dl ;dl(乘数)为10,al(被乘数),乘积在ax中mov bx,axmov ah,1int 21hand al,0fh ;只留下al低位clc ;清除进位标志,置cf为0add bl,aladc bh,0mov dl,0ah ;换行和置首位mov ah,02hint 21hmov dl,0dhmov ah,02hint 21hmov dx,offset string2mov ah,09hint 21hmov ah,1int 21hmov dh,alsub dh,30hmov dl,0ah ;换行和置首位mov ah,2int 21hmov dl,0dhmov ah,2int 21hmov ax,bxmov bx,0001hmov di,offset relop1:div dh add ah,30hmov [di],ahcbw ;CBW :字节转换为字执行的操作:AL的内容符号扩展到AH,形成AX中的字。即如果(AL)的最高有效位为0,则(AH)=0add di,bx ;如(AL)的最高有效位为1,则(AH)=0FFH。cmp al,0ja lop1mov cx,08hmov di,offset reclc ;清除进位标志位,置cf等于0adc di,cxlop2:sub di,bx mov dl,[di]mov ah,2int 21hloop lop2mov ah,4chint 21hcode endsend start
显示全部