🍪
cookielau
  • Introduction
  • Machine Learning
    • Distributed
      • Bookmarks
    • NLP
      • Transformers
    • MLC
      • Tensor Program Abstraction
      • End-to-End Module Execution
  • Framework
    • PyTorch
      • Bookmarks
      • Model
      • Shared
      • Miscellaneous
    • Tensorflow
      • Bookmarks
      • Model
      • Shared
      • Miscellaneous
    • CUDA
      • Bookmarks
    • DeepSpeed
    • Bagua
      • Model
      • Optimizer
    • Others
      • Bookmarks
  • About Me
    • 2022-04-28
  • Random Thoughts
  • Archives
    • CPP
      • Bookmarks
      • Container
      • Algorithm
      • FILE CONTROL
      • Virtual Table
      • Assembly
      • Key Words
      • Problems
      • Others
    • JAVA
      • String Container
      • Maps
    • PYTHON
      • Bookmarks
      • Python Tools
        • Batch Rename
        • Combine Excel
        • Excel Oprations
        • Read Write Excel
        • Rotate PDF
      • Library
        • Pandas Notes
        • Numpy Notes
        • Json Notes
      • Spider
        • Selenium Install
        • Selenium Locating
        • Selenium Errors
        • Selenium Basics
      • Django
        • Start Up
      • Others
    • LINUX
      • Installation
      • Cli Tools
      • WSL
      • Bugs
    • JUNIOR2
      • Economics
        • Chapter 0x01 经济管理概述
        • Chapter 0x02 微观市场机制分析
        • Chapter 0x03 生产决策与市场结构
        • Chapter 0x04 宏观经济市场分析
        • Chapter 0x05 管理的职能
        • Chapter 0x06 生产系统结构与战略
        • Chapter 0x0b 投资项目经济评价
        • Chapter 0x0f 投资项目经济评价
      • Computer Network
        • 概述
        • 分层模型
        • 物理层
        • 数据链路层
        • 网络层
        • 传输层
        • 应用层
        • HTTP(s)实验
        • [Practice]
      • Software Engineering
        • Introduction
        • Demand Analysis
        • Task Estimation
        • Presentation
      • Network Security
        • Chapter 0x01 概述
        • Chapter 0x02 密码学
        • Chapter 0x03 公钥体制
        • Chapter 0x04 消息认证
        • Chapter 0x05 密钥管理
        • Chapter 0x06 访问控制
        • Assignments
      • x86 Programming
        • Basic Knowledge
        • Program Design
        • System Interruption
        • Frequently used functions
    • MD&LaTex
      • Markdown
      • LaTex
    • NPM
      • NPM LINK
    • MyBlogs
      • 2020BUAA软工——“停下来,回头看”
      • 2020BUAA软工——“初窥构建之法”
      • 2020BUAA软工——“上手软件工程,PSP初体验!”
      • 2020BUAA软工——“深度评测官”
      • 2020BUAA软工——“并肩作战,平面交点Pro”
    • SC
      • PAC 2022
        • Lectures
      • OpenMP & MPI
        • MPI Overview
        • Message Passing Programming
        • OpenMP Overview
        • Work Sharing Directives
        • Annual Challenge
        • Future Topics in OpenMP
        • Tasks
        • OpenMP & MPI
    • Hardware
      • Nvidia GPU
        • Frequent Error
        • Memory Classification
        • CUDA_7_Streams_Simplify_Concurrency
        • Optimize_Data_Transfers_in_CUDA
        • Overlap_Data_Transfers_in_CUDA
        • Write_Flexible_Kernels_with_Grid-Stride_Loops
        • How_to_Access_Global_Memory_Efficiently
        • Using_Shared_Memory
      • Intel CPU
        • Construction
        • Optimization
        • Compilation
        • OpenMP
    • English
      • Vocab
      • Composition
    • Interview
      • Computer Network
Powered by GitBook
On this page
  • System
  • 标准模板
  • String Operations
  • 读取字符串
  • 检测一个字符串中有多少字符
  • 比较两个串的大小

Was this helpful?

  1. Archives
  2. JUNIOR2
  3. x86 Programming

Frequently used functions

16th Jun, 2020

System

标准模板

stack  segment para stack
    stack_area dw 100 dup(?)
    stack_btm equ $-stack_area
stack ends

data segment para
divisor     dw 10000, 1000, 100, 10, 1
len equ 126
buffer db len
       db ?
       db len dup(?)
data ends

code segment para
     assume cs:code, ds:data, ss:stack
main proc far

     mov ax, stack
     mov ss, ax
     mov ax, data
     mov ds, ax
     mov es, ax
     mov sp, stack_btm

     ; do something


exit:
     mov ax, 4c00h
     int 21h
main endp
code ends
     end main

String Operations

读取字符串

; 先在data段中定义
data segment para
...
len equ 126
buffer db len ; 预定义的最大允许长度
       db ?   ; 缓冲区内读取到的的实际长度
       db len dup(?)
...
data ends

...
buffer_read:
     mov dx, offset buffer ; DS:DX 为缓冲区的首地址
     mov ah, 0ah ; 调用0ah是读取到缓冲区,回车为结尾
     int 21h ; 系统调用

     mov cl, buffer+1 ; 读缓冲区内字符串实际长度
     xor ch, ch
     mov si, offset buffer+2
     push bx
     mov bx, offset buffer+2
     add bx, cx
     mov byte ptr [bx], 0 ; asciiz
     inc bx
     mov byte ptr [bx], '$'
     pop bx

end_buffer_read:
     do_something

检测一个字符串中有多少字符

     ...
     push es
     push ds
     pop es
     mov di, offset string
     mov cx, strlen ; 字符长度,buffer+1
     mov al, 't' ; char to find
     cld ; 设置DF=0,字符串低地址向高地址走
     mov bx, 0
continueScan:
     repnz scasb ; 按字节寻找
     ; 如果只是要检测有无,在这里直接 JZ FOUND 即可
     jnz endScan ; ZF=0说明已经到达CX=0且最后一位不等,直接退出
     inc bx ; bx统计出现次数
     cmp cx, 0 ; cx!=0 说明后面还有字符
     jnz continueScan
endScan:
     pop es
     ...

比较两个串的大小

; 都先使用上面的字符串读取,在末尾加上一个 0h,'$',0是可以保证一个字符串结束就能出现结果,否则'$'会被正常算进去

     push es ; 先保存ES
     push ds
     pop es 
     mov si, offset string1
     mov di, offset string2
     mov cx, strlen
     cld
     repz cmpsb ; 没比完且相同就继续比,直到CX=0或者ZF=0
     jz equalCase ; 结束repz且ZF=1说明相等
     ja largerCase ; 大于0说明string1>string2
     ; smallerCase string1<string2

     pop es ; 结束后返还ES
PreviousSystem InterruptionNextMD&LaTex

Last updated 4 years ago

Was this helpful?