当前位置:网站首页>Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
2022-07-25 22:43:00 【Zombotany Zhiyong】
Catalog
Experiment 1 Branch programming
The experimental requirements :
Count the number of negative and non negative numbers in the signed byte array
Experimental code
org 100h
.MODEL TINY
.STACK 100
.DATA
arr db -10,0,127,-128,63,67,8,-16,1,2
negcnt db 0
poscnt db 0
.CODE
start: mov ax,@data
mov ds,ax
mov es,ax
mov cx,10 ; The array length is 10
lea bx,arr ;bx Point to arr
mov negcnt,0 ; negative 0 individual
mov poscnt,0 ; Nonnegative number 0 individual
mov dx,0
loopst: cmp cx,0
jle loopend
cmp dx,[bx] ; Compare 0 and bx The size of the number pointed
jg label2
inc poscnt ; Non negative count
jmp exit
label2: inc negcnt ; Negative count
exit: dec cx
inc bx
jmp loopst
loopend:jmp $
end start
ret
Experiment two Loop programming
The experimental requirements
Bubble sorting method is used to sort the length of 20 Incremental sorting of word data .
Experimental code
org 100h
.MODEL TINY
.STACK 100
.DATA
arr dw -128,127,-1,0,1,129,-129,32767,-32768,32766,-32767,1,0,1024,-1023,16384,45,-46,-5,6
len equ 20
.CODE
start: mov ax,@data
mov ds,ax
mov es,ax
mov cx,len-1
loop1:
push cx
mov bx,offset arr
loop2:
mov dx,[bx]
cmp dx,[bx+2]
jle next
xchg dx,[bx+2]
xchg dx,[bx]
next:
inc bx
inc bx
loop loop2
pop cx
loop loop1
mov ax,4C00H
jmp $
end start
ret
Experiment three Subroutine design
The experimental requirements :
Choose to enter an unsigned integer from the keyboard , Judge whether it is a prime number and display relevant prompt information on the display . The function of judging whether a number is a prime number is realized by subroutine .
org 100h
.MODEL TINY
.STACK 100
.DATA
msg1 db 'the number is a prime',0dh,0ah,'$'
msg2 db 'the number is not a prime',0dh,0ah,'$'
innum dw 0
indig db 0
divnum db 0
ten db 10
res db 0
.CODE
start:
mov ax,@data
mov ds,ax
mov es,ax
call input1;// Input
call isp ;// Judge whether it is a prime
mov ah,09h
cmp res,0;// Not primes
je exit3
mov dx,offset msg1;// Prime number
int 21h
jmp exit4
exit3:
mov dx,offset msg2;// Not primes , Output
int 21h
exit4: jmp $
input1 proc near
mov ax,0h
mov innum,0h;// Store complete input data
label1:
mov ah,01h
mov al,02h
int 21h
cmp al,'0'
jl exit
cmp al,'9'
jg exit;// It is detected that it is not a number , It indicates that the data input is completed
sub al,'0'
mov indig,al;//indig Represents the single digit of the current number
mov ax,innum;// Previously entered data innum*10 Add the current digit , Splice to get the current number
mul ten
mov innum,ax
mov al,indig
cbw
add innum,ax;// The stitching is complete
jmp label1;// Enter the next digit
exit:
ret
input1 endp
isp proc near
mov ax,innum
cmp ax,2
jb exit0 ;//0 and 1 Not primes
je exit1;//2 Prime number
mov divnum,2 ;// The divisor begins with 2
mov cx,innum
sub cx,1;//cx Enter a number for -1, Is the maximum value of the cycle
loop1:
push ax
div divnum;//ax/divnum
cmp ah,0;// Remainder is 0, Is the sum
jz exit0
inc divnum
cmp divnum,cx
pop ax
jb loop1
jge exit1;//2~n-1 I've tried all the numbers , Not enough , Prime number
exit1:
mov res,1
exit0:
ret
isp endp
end start
end
边栏推荐
- [training day13] backpack [dynamic planning] [greed]
- Binder原理
- Wkid in ArcGIS
- 【集训DAY15】油漆道路【最小生成树】
- Can generic types be used in array
- XSS collect common code
- Two methods of printing strings in reverse order in C language
- Tree view model example of QT
- Explore the use of self increasing and self decreasing operators
- 新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法
猜你喜欢

Simple setting method of search box

Structure principle of micro ball vibration switch with chip

关于getchar和scanf的使用示例及注意点

Use of qvariant

Two methods of printing strings in reverse order in C language

Vodak software: Smart City solution

Matrix of C language

Xiaobai programmer's sixth day

沃达德软件:智慧城市方案
![[training Day12] x equation [high precision] [mathematics]](/img/4f/51d902e925f9ec60da46d161ed4d17.png)
[training Day12] x equation [high precision] [mathematics]
随机推荐
(1) DDL, DML, DQL, DCL and common data types
scrapy无缝对接布隆过滤器
The price of dividing gold bars
Qt中文编程遇C2001错误,提示“常量中有换行符”
自媒体人必备的4个素材网站,再也不用担心找不到素材
Today, learn about the use of lists, hyperlinks, image tags, and audio and video
数据平台下的数据治理
关于getchar和scanf的使用示例及注意点
Force deduction solution summary 919 complete binary tree inserter
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
XSS collect common code
[MySQL rights] UDF rights (with Malaysia)
Vodak software: Smart City solution
ML-Numpy
Method of converting MAPGIS format to ArcGIS
[training Day12] tree! Tree! Tree! [greed] [minimum spanning tree]
xss-工具-Beef-Xss安装以及使用
Simple application of partial labels and selectors
Xiaobai programmer's fifth day
【集训DAY15】简单计算【树状数组】【数学】