当前位置:网站首页>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
边栏推荐
- Force deduction solution summary 919 complete binary tree inserter
- Short circuit effect of logical operators short circuit and short circuit or
- 自媒体人必备的4个素材网站,再也不用担心找不到素材
- 字符型常量和字符串常量的区别?
- Why should we launch getaverse?
- XSS collect common code
- We media people must have four material websites, and don't worry about finding materials anymore
- Xiaobai programmer's seventh day
- [PMP learning notes] Chapter 1 Introduction to PMP System
- It's over. I went to work for three months and became bald
猜你喜欢

(1) DDL, DML, DQL, DCL and common data types

JVM内存区域

Google analyzes how UA can be transferred to the latest version of GA4

Arcgis10.2 configuring postgresql9.2 standard tutorial

QT Chinese programming encounters c2001 error, prompting "there is a newline character in the constant"

MatrixCube揭秘102——300行实现的完整分布式存储系统MatrixKV

自媒体人必备的4个资源工具,每一个都很实用

Interview question 17.11. word distance ●●

Qt5.12 installation error prompt: c:\qt5.12.11\vcredist\vcredist_ msvc2019_ x86.exe /norestart /q

The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)
随机推荐
Can generic types be used in array
Share two music playing addresses
Examples and points for attention about the use of getchar and scanf
Array中可以用泛型吗
Data type conversion
Matrix of C language
The price of dividing gold bars
【MySQL提权】UDF提权(附带大马)
Box model (2)
Today, learn about the use of lists, hyperlinks, image tags, and audio and video
TFrecord写入与读取
【集训DAY15】好名字【hash】
[training Day11] Calc [mathematics]
Binder原理
软件测试 pytest pytest的命名规则 用例的前后置 conftest.py 定制allure报告 @pytest.mark.parametrize()装饰器作数据驱动
点亮字符串中所有需要点亮的位置,至少需要点几盏灯
[training Day12] x equation [high precision] [mathematics]
[training day13] Internet [concurrent search]
Use of qvariant
对需求的内容进行jieba分词并按词频排序输出excel文档