Last active
December 3, 2019 05:38
-
-
Save alexsunday/0c5611cab38133593af00e71bcc64be7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assume cs:code, ds:data, ss:stack | |
data segment | |
; 编写一个子程序,将下列字符串小写字母变成大写 | |
; 小写字母必须在 [0x61, 0x7A] 闭区间 | |
; 并分别显示在屏幕上 | |
db "Beginer's All - purpose Symbolic Instruction Code.", 0 | |
data ends | |
stack segment stack | |
db 128 dup (0) | |
stack ends | |
code segment | |
start: | |
; 栈 | |
mov ax, stack | |
mov ss, ax | |
mov sp, 128 | |
; 数据 | |
mov ax, data | |
mov ds, ax | |
mov si, 0 | |
; 指定显示位置 | |
mov dh, 10 | |
mov dl, 1 | |
mov cl, 00000010B | |
call show_str | |
call toLower | |
mov dh, 11 | |
call show_str | |
quit: | |
mov ax, 4c00H | |
int 21H | |
toLower: | |
push cx | |
push si | |
mov si, 0 | |
mov cx, 0 | |
to_lower: | |
mov cl, ds:[si] | |
jcxz to_lower_end | |
cmp cl, 'a' | |
jb continue | |
cmp cl, 'z' | |
ja continue | |
; 转大写,即 cl - 30H | |
and byte ptr ds:[si], 11011111B | |
continue: | |
inc si | |
jmp to_lower | |
to_lower_end: | |
pop si | |
pop cx | |
ret | |
show_str: | |
; 显示字符串,show_str 在指定位置,使用指定颜色,显示0结尾的字符串 | |
; dh 行号,dl 列号,cl 颜色 ds:si 指向字符串首地址 | |
; 0 行 第0列 偏移为 0 | |
; 1 行 第0列 偏移为 160 第 N 行 m 列,偏移为 160 * n + 2 * m | |
push ax | |
push cx | |
push dx | |
push si | |
push di | |
mov ax, 0B800H | |
mov es, ax | |
; 计算首地址 di | |
mov al, dh | |
mov ah, 160 | |
mul ah | |
push ax | |
mov al, dl | |
mov ah, 2 | |
mul ah | |
pop di | |
add di, ax | |
mov ah, cl | |
mov cx, 0 | |
show_byte: | |
mov al, ds:[si] | |
mov es:[di], ax | |
mov cl, al | |
jcxz show_end | |
inc si | |
add di, 2 | |
jmp show_byte | |
show_end: | |
pop di | |
pop si | |
pop dx | |
pop cx | |
pop ax | |
ret | |
code ends | |
end start |
Author
alexsunday
commented
Dec 3, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment