当前位置:网站首页>Assembly base code example
Assembly base code example
2022-04-23 06:46:00 【Round moon】
String passing
data segment
src db "hello!"
data ends
extra segment
new db 6 dup("0")
extra ends
code segment
assume cs:code,ds:data,es:extra
start:
mov ax,data
mov ds,ax
mov ax,extra
mov es,ax
lea si,src
lea di,new
mov cx,6
cld
rep movsb
code ends
end start
Output single symbol
Indicates that a single... Is output ascii The value of the code
prog1 segment
assume cs:prog1
start:
mov dl,'?';ASCII code
mov ah,2
int 21h
mov ax,4c00h
int 21h
prog1 ends
end start
Square the number
data segment
table db 0,1,4,9,16,25,36,49,64,81
buf db "Please input a number(0~9):",0DH,0AH,"$"
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset buf
mov ah,9h
int 21h
mov ah,1
int 21h
and al,0fh
mov bx,offset table
mov ah,0
add bx,ax
mov al,[bx]
mov ax,4c00h
int 21h
code ends
end start
Sum of two numbers
data segment
a1 db 56h,78h
a2 db 4fh,9ah
sum db 3 dup(0)
data ends
code segment
assume cs:code,ds:data
begin:
mov ax,data
mov ds,ax
mov bx,0
clc
mov al,a1[bx]
adc al,a2[bx]
mov sum[bx],al
inc bx
mov al,a1[bx]
adc al,a2[bx]
mov sum[bx],al
jnc STOP
inc bx
mov al,1
mov sum[bx],al
STOP:
mov ax,4c00h
int 21h
code ends
end begin
Print transcripts
al Deposit 16 Binary grade
Output the corresponding score
cmp al,60
jb fail
cmp al,85
jae good
mov al,"P"
jmp print
fail:
mov al,'F'
jmp print
good:
mov al,"G"
jmp print
print:
mov dl,al
mov ah,2
int 21h
mov ax,4c00h
int 21h
Character statistics
Statistics The number of capital letters and other letters
data segment
buf db "PRINT","abc",35h,52h,30h,08h
count equ $-buf
num db 3 dup(0)
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ch,count
mov bx,0
mov dx,0
loop1:
mov ah,buf[bx]
cmp ah,30h
jl next
cmp ah,39h
jg abc
inc dh
jmp next
abc:
cmp ah,41h
jl next
cmp ah,5ah
jg next
inc dl
next:
inc bx
dec ch
jnz loop1
mov num,dh
mov num+1,dl
mov ah,count
sub ah,dh
sub ah,dl
mov num+2,ah
mov ax,4c00h
int 21h
code ends
end start
Search for maximum
data segment
save dw 1234h,3200h,4832h,5600h
count equ ($-save)/2
max dw ?
data ends
code segment
assume code:cs,data:ds
start:
mov ax,data
mov ds,ax
mov bx,0
mov cx,count
dec cx
mov dx,save[0]
mov max,dx
again:
add bx,2
mov dx,save[bx]
cmp max,dx
jg next
mov max,dx
next:
loop again
code ends
end start
BCD Add
data segment
A DB 44h,33h,22h,11h
B DB 88h,77h,66h,55h
ans 5 dup(0)
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,0
mov cx,4
again:
mov al,A[bx]
add al,B[bx]
daa
mov ans[bx],al
jnc NEXT
add A[bx+1],1
NEXT:
inc bx
loop again
code ends
end start
Bubble sort
data segment
list dw 12,7,19,8,24
count equ ($-list)/2
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov cx,count-1
loop1:
mov dx,cx
mov bx,0
loop2:
mov ax,list[bx]
cmp ax,list[bx+2]
JGE NO_CHANGE
xchg ax,list[bx+2]
mov list[bx],ax
NO_CHANGE:
add bx,2
loop loop2
mov cx,dx
loop loop1
mov ax,4c00h
int 21h
code ends
end start
Output number
AL position 62H Corresponding to decimal number 98
Bin_ascii proc near
mov ah,0
mov bl,10
div bl
xchg ah,al
add ax,3030h
mov cx,ax
mov dl,ch
mov ah,2
int 21h
mov dl,cl
int 21h
ret
Bin_ascii endp
Store numbers
Output decimal numbers , Deposit in bx in
DEC_BIN proc near
mov bx,0
get_char:
mov ah,1
int 21h
cmp al,0dh
je exit
sub al,30h
jl exit
cmp al,9
jg exit
cbw
xchg ax,bx
mov cx,10
mul cx
xchg ax,bx
add bx,ax
jmp get_char
exit:
ret
DEC_BIN endp
Output 16 Base number
take bx The data in is output in hexadecimal
BIN_HEX proc near
mov cx,4
begin:
mov dl,bh
shr dl,4
add dl,30h
cmp dl,'9'
jl Display
sub dl,'9'+1
add dl,"A"
Display:
mov ah,2
int 21h
shl bx,4
loop begin
BIN_HEX endp
Hexadecimal conversion BCD
What needs to be noted here is , When dividing bytes ,DX It's a senior eight
bin_bcd proc near
mov ax,04D2h
cmp ax,9999
jbe tran
jmp exit
tran:
mov dx,0
mov cx,1000
div cx
xchg ax,dx
shl bx,4
add bx,dx
mov dx,0
mov cx,100
div cx
xchg ax,dx
shl bx,4
add bx,dx
mov dx,0
mov dx,0
mov cx,10
div cx
xchg ax,dx
shl bx,4
add bx,dx
mov dx,0
mov cx,1
div cx
xchg ax,dx
shl bx,4
add bx,dx
mov dx,0
exit:
ret
bin_bcd endp
seek BCD and
Methods using procedure calls
data segment
num1 db 44h,33h,22h,11h
num2 db 88h,77h,66h,55h
sum db 5 dup(0)
data ends
stack segment stack
dw 50 dup()
top label word
stack ends
code segment
main proc far
assume cs:code,ds:data,ss:stack
start:
mov ax,stack
mov ss,ax
mov sp, offset top
push ds
push 0
mov ax,data
mov ds,ax
mov es,ax
lea si,num1
lea bx,num2
lea di,sum
clc
cld
mov ah,0
mov cx,4
loop1:
call add_b
loop loop1
adc ah,0
mov al,ah
stosb
ret
main endp
add_b proc near
lodsb
adc al,[bx]
daa
stosb
inc bx
ret
add_b endp
code ends
end main
Fibonacci
data segment
Fibonacci db 1,1,5 dup()
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov cx,5
mov dh,0
mov dl,1
Loop1:
mov bx,0
mov bl,dh
mov ah,Fibonacci[bx]
mov bl,dl
mov al,Fibonacci[bx]
add ah,al
inc dh
inc dl
inc bx
mov Fibonacci[bx],ah
loop Loop1
code ends
end start
版权声明
本文为[Round moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549499486.html
边栏推荐
猜你喜欢
![[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms](/img/fb/3d3cf54dc5b67ce42d60e0fe63baa6.png)
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms

Initialization of classes and objects (constructors and destructors)

C语言实用小技巧合集(持续更新)
![[UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)](/img/4f/315a9b4cd85ebaad39cfa985dea45b.png)
[UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)

【UDS统一诊断服务】(补充)五、ECU bootloader开发要点详解 (2)

C#【文件操作篇】PDF文件和图片互相转换

Eigen 学习总结

For() loop parameter call order

copy constructor

CUDA环境安装
随机推荐
Call procedure of function
PHP junior programmers, take orders and earn extra money
【UDS统一诊断服务】四、诊断典型服务(6)— 输入输出控制单元(0x2F)
类和对象
token详解以及应用原理
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
ES6面试题(参考文档)
[learn] HF net training
vs中能编译通过,但是会有红色下划线提示未定义标示符问题
卷积神经网络实现CIFAR100数据集分类
搭建jpress个人博客
vs中的多字节与unicode
猜數字遊戲
Vs can be compiled, but there will be a red underline to indicate the problem of undefined identifiers
拷贝构造函数
Jeu de devinettes
Eigen 库常用基本用法 备忘
Understanding of SSH public key and private key
C语言进阶要点笔记5
[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit