我的汇编语言程序模板
来源:互联网 发布:2016印度宏观经济数据 编辑:程序博客网 时间:2024/05/17 07:59
这里只有一些最基础的功能的代码,有时间继续完善。
本博客不适合学习及使用。
data segment ;input data segment code here stack_store word 0fffh dup(0) ;reg stack stack_top word 0000h ;reg stack push_ax_store_ax word 0000h push_ax_store_bx word 0000h push_ax_store_cx word 0000h push_ax_store_dx word 0000h print_hex_store_var word 0000h local_ax_store word 0000h pause_str byte "press any key to continue...",10,13,'$' endl_str byte 10,13,'$' tab_str byte " ",'$' ax_str byte "ax:",'$' bx_str byte "bx:",'$' cx_str byte "cx:",'$' dx_str byte "dx:",'$'data endsstack segment ;input stack segment code herestack endscode segment assume cs:code,ds:data,ss:stackpush_ax: ;push ax into reg stack mov push_ax_store_ax,ax ;store flags mov push_ax_store_bx,bx lea bx,stack_store add bx,stack_top ;get stack top mov [bx],ax add stack_top,0002h mov ax,push_ax_store_ax ;reget flags mov bx,push_ax_store_bx retpop_ax: ;pop a value from reg stack to ax mov push_ax_store_bx,bx ;store flags lea bx,stack_store sub stack_top,0002h add bx,stack_top ;get stack top mov ax,[bx] mov bx,push_ax_store_bx ;reget flags retstore_reg: ;store reg into reg stack mov local_ax_store,ax call push_ax mov ax,bx call push_ax mov ax,cx call push_ax mov ax,dx call push_ax mov ax,local_ax_store retreget_reg: ;reget reg from reg stack call pop_ax mov dx,ax call pop_ax mov cx,ax call pop_ax mov bx,ax call pop_ax ;mov ax,ax rettrans_dl_hex: ;trans late dl to hex char cmp dl,09h ja greater_than_09h add dl,30h ret greater_than_09h: sub dl,0ah add dl,41h ;'a'=65=41h retoutput_dl_char: call store_reg mov ah,02h int 21h call reget_reg retprint_hex_ax: ;output ax as a hex number mov print_hex_store_var,ax call store_reg mov bx,print_hex_store_var and bx,0f000h mov cl,0ch shr bx,cl mov dl,bl call trans_dl_hex call output_dl_char mov bx,print_hex_store_var and bx,0f00h mov cl,08h shr bx,cl mov dl,bl call trans_dl_hex call output_dl_char mov bx,print_hex_store_var and bx,00f0h mov cl,04h shr bx,cl mov dl,bl call trans_dl_hex call output_dl_char mov bx,print_hex_store_var and bx,000fh mov dl,bl call trans_dl_hex call output_dl_char call reget_reg retadd_stack_ax: ;add ax elements into the stack call store_reg mov cl,02h shl ax,cl add stack_top,ax call reget_reg retprint_str_dx: ;print a string at dx call store_reg mov ah,09h int 21h call reget_reg retprint_endl: ;print endl call store_reg lea dx,endl_str call print_str_dx call reget_reg retpause_program: ;"press any key to continue..." call store_reg lea dx,pause_str call print_str_dx call getch_ax call reget_reg retgetch_ax: ;get a char from key board (without enter) to ax call store_reg mov ah,07h int 21h mov ah,00h mov local_ax_store,ax call reget_reg mov ax,local_ax_store retdebug_reg_val: ;output ax bx cx dx 's value mov local_ax_store,ax ;store value mov push_ax_store_bx,bx mov push_ax_store_cx,cx mov push_ax_store_dx,dx call store_reg lea dx,ax_str ;ax output call print_str_dx mov ax,local_ax_store call print_hex_ax lea dx,tab_str call print_str_dx lea dx,bx_str ;bx output call print_str_dx mov ax,push_ax_store_bx call print_hex_ax lea dx,tab_str call print_str_dx lea dx,cx_str ;cx output call print_str_dx mov ax,push_ax_store_cx call print_hex_ax lea dx,tab_str call print_str_dx lea dx,dx_str ;dx ouput call print_str_dx mov ax,push_ax_store_dx call print_hex_ax lea dx,tab_str call print_str_dx call print_endl ;endl output call reget_reg retstart: ;program start here mov ax,data mov ds,ax ;input code segment code here call pause_program ;pause end mov ah,4ch int 21hcode endsend start
新增功能:十六进制数的输入
data segment ;input data segment code here stack_store word 0fffh dup(0) ;reg stack stack_top word 0000h ;reg stack push_ax_store_ax word 0000h push_ax_store_bx word 0000h push_ax_store_cx word 0000h push_ax_store_dx word 0000h print_hex_store_var word 0000h local_ax_store word 0000h pause_str byte "press any key to continue...",10,13,'$' endl_str byte 10,13,'$' tab_str byte " ",'$' ax_str byte "ax:",'$' bx_str byte "bx:",'$' cx_str byte "cx:",'$' dx_str byte "dx:",'$' scan_hex_store word 0000h scan_hex_input byte 5,0,5 dup('$') scan_hex_input_len word 0000h clear_num_str byte 13,"[hex input]"," ",8,8,8,8,8,'$' end_num_str byte "[you input]",'$'data endsstack segment ;input stack segment code herestack endscode segment assume cs:code,ds:data,ss:stackpush_ax: ;push ax into reg stack mov push_ax_store_ax,ax ;store flags mov push_ax_store_bx,bx lea bx,stack_store add bx,stack_top ;get stack top mov [bx],ax add stack_top,0002h mov ax,push_ax_store_ax ;reget flags mov bx,push_ax_store_bx retpop_ax: ;pop a value from reg stack to ax mov push_ax_store_bx,bx ;store flags lea bx,stack_store sub stack_top,0002h add bx,stack_top ;get stack top mov ax,[bx] mov bx,push_ax_store_bx ;reget flags retstore_reg: ;store reg into reg stack mov local_ax_store,ax call push_ax mov ax,bx call push_ax mov ax,cx call push_ax mov ax,dx call push_ax mov ax,local_ax_store retreget_reg: ;reget reg from reg stack call pop_ax mov dx,ax call pop_ax mov cx,ax call pop_ax mov bx,ax call pop_ax ;mov ax,ax rettrans_dl_hex: ;trans late dl to hex char cmp dl,09h ja greater_than_09h add dl,30h ret greater_than_09h: sub dl,0ah add dl,41h ;'a'=65=41h retoutput_dl_char: call store_reg mov ah,02h int 21h call reget_reg retprint_hex_ax: ;output ax as a hex number mov print_hex_store_var,ax call store_reg mov bx,print_hex_store_var and bx,0f000h mov cl,0ch shr bx,cl mov dl,bl call trans_dl_hex call output_dl_char mov bx,print_hex_store_var and bx,0f00h mov cl,08h shr bx,cl mov dl,bl call trans_dl_hex call output_dl_char mov bx,print_hex_store_var and bx,00f0h mov cl,04h shr bx,cl mov dl,bl call trans_dl_hex call output_dl_char mov bx,print_hex_store_var and bx,000fh mov dl,bl call trans_dl_hex call output_dl_char call reget_reg retadd_stack_ax: ;add ax elements into the stack call store_reg mov cl,02h shl ax,cl add stack_top,ax call reget_reg retprint_str_dx: ;print a string at dx call store_reg mov ah,09h int 21h call reget_reg retprint_endl: ;print endl call store_reg lea dx,endl_str call print_str_dx call reget_reg retpause_program: ;"press any key to continue..." call store_reg lea dx,pause_str call print_str_dx call getch_ax call reget_reg retgetch_ax: ;get a char from key board (without enter) to ax call store_reg mov ah,07h int 21h mov ah,00h mov local_ax_store,ax call reget_reg mov ax,local_ax_store retdebug_reg_val: ;output ax bx cx dx 's value mov local_ax_store,ax ;store value mov push_ax_store_bx,bx mov push_ax_store_cx,cx mov push_ax_store_dx,dx call store_reg lea dx,ax_str ;ax output call print_str_dx mov ax,local_ax_store call print_hex_ax lea dx,tab_str call print_str_dx lea dx,bx_str ;bx output call print_str_dx mov ax,push_ax_store_bx call print_hex_ax lea dx,tab_str call print_str_dx lea dx,cx_str ;cx output call print_str_dx mov ax,push_ax_store_cx call print_hex_ax lea dx,tab_str call print_str_dx lea dx,dx_str ;dx ouput call print_str_dx mov ax,push_ax_store_dx call print_hex_ax lea dx,tab_str call print_str_dx call print_endl ;endl output call reget_reg retretrans_hex_ax: cmp ax,61h ;small jl retrans_below_small sub ax,20h ;-small retrans_below_small: cmp ax,41h ;'a' jge retrans_geater_than_65h sub ax,30h ret retrans_geater_than_65h: sub ax,41h add ax,0ah retscan_hex_ax: ;read in a hex with four bits call store_reg scan_hex_ax_again: lea dx,clear_num_str call print_str_dx mov bx,0000h lea dx,scan_hex_input mov bp,dx mov ah,0ah int 21h ;input string mov dx,0000h mov dl,[bp+01h] ;get len cmp dx,04h jnz scan_hex_ax_again mov ah,00h ;first bit mov al,[bp+02h] call retrans_hex_ax mov cl,04h shl bx,cl add bx,ax mov ah,00h ;sec bit mov al,[bp+03h] call retrans_hex_ax mov cl,04h shl bx,cl add bx,ax mov ah,00h ;third bit mov al,[bp+04h] call retrans_hex_ax mov cl,04h shl bx,cl add bx,ax mov ah,00h ;forth bit mov al,[bp+05h] call retrans_hex_ax mov cl,04h shl bx,cl add bx,ax mov local_ax_store,bx ;store call reget_reg mov ax,local_ax_store call print_endl lea dx,end_num_str call print_str_dx call print_hex_ax call print_endl retstart: ;program start here mov ax,data mov ds,ax ;input code segment code here call scan_hex_ax call pause_program ;pause end mov ah,4ch int 21hcode endsend start
阅读全文
1 0
- 我的汇编语言程序模板
- 我的第一个汇编语言程序:HelloWorld
- 汇编语言程序的基础
- 汇编语言-多个段的程序
- 汇编语言的程序格式
- 我的网页模板抓取程序
- 汇编语言程序的程序壳
- 我的汇编语言语言作业
- 我汇编语言的学习经历
- 汇编语言的Hello world程序
- 编译后的汇编语言程序
- 8086汇编语言 调用函数的模板
- 汇编语言程序调用C程序的原则
- 汇编语言程序
- 汇编语言程序
- 我所在的坛子----x64asm 汇编语言论坛
- 我的第一篇博客 8086汇编语言
- 汇编语言命令参数程序的编写
- poj 1855:Mint 搜索
- linux 10
- JDBC数据库连接池实现原理(手动实现)
- 在 ASP.NET Core 项目中实现小写的路由URL
- faster-rcnn笔记
- 我的汇编语言程序模板
- (crm笔记1-1) 框架的搭建
- Qt 学习之路 2(64):使用 QJsonDocument 处理 JSON
- 【Java】去除List中的重复值并按照从小到大排列
- Xcode9提示"Safe Area Layout Guide before iOS 9.0"
- STL中的内存分配方式
- Tomcat源码分析--国际化--StringManager类
- Count and Say
- 一周AI看点 | 北航设立全国首个人工智能专业,前IBM沃森首席科学家任京东副总裁