当前位置:网站首页>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
边栏推荐
- C语言 #和##的使用
- Class inheritance and derivation
- 信息学一本通-小球
- Notes on advanced points of C language 5
- Introduction to nonparametric camera distortion model
- C语言实现memcpy、memset、strcpy、strncpy、strcmp、strncmp、strlen
- Round up a little detail of the round
- Palindromic Primes
- [UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
- 汇编 32位无符号加法计算器
猜你喜欢
![[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)](/img/10/bd39bb03f5456a412650596208a391.png)
[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)

【UDS统一诊断服务】一、诊断概述(1)— 诊断概述

搭建jpress个人博客

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

QT icon application
![C [document operation] PDF files and pictures are converted to each other](/img/6b/0742aa3eb45fbca091d6d20bc55326.png)
C [document operation] PDF files and pictures are converted to each other

C语言实用小技巧合集(持续更新)

JS高频面试题

C语言的浪漫

在visual stdio中运行qt程序
随机推荐
SQLite compilation
客户端软件增量更新
猜數字遊戲
C language advanced notes 3
汇编基础代码示例
猜数字游戏
Log writing method (with time)
Uniapp encapsulates request
【UDS统一诊断服务】四、诊断典型服务(6)— 输入输出控制单元(0x2F)
【UDS统一诊断服务】三、应用层协议(2)
[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
往String原型上封装一个时间戳转日期的方法
copy constructor
[UDS unified diagnosis service] i. diagnosis overview (1) - diagnosis overview
Makefile基础、常用函数及通用Makefile
JS高频面试题
Round up a little detail of the round
[UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit
带默认模板实参的类模板与模板模板形参的匹配
PN结、二极管原理详解与应用