//2020年08月13日 05时26分36秒
assume cs:codesg
codesg segment
mov ax, 2000h
mov ss, ax
mov sp, 0
add sp, 4
pop ax
pop bx
push ax
push bx
pop ax
pop bx
mov ax, 4c00h
int 21
codesg ends
end
assume cs:codesg
codesg segment
mov ax, 2000h
mov ds, ax
mov bx, 1000h
mov ax, [bx]
inc bx
inc bx
mov [bx], ax
inc bx
inc bx
mov [bx], ax
inc bx
mov [bx], al
inc bx
mov [bx], al
mov ax, 4c00h
int 21
codesg ends
end
//2020年08月14日 05时48分32秒
assume cs:codesg
codesg segment
mov ax, 2
mov cx, 11
s: add ax, ax
loop s
mov ax, 4c00h
int 21
codesg ends
end
//2020年08月15日 06时05分56秒
assume cs:codesg
codesg segment
mov ax, 0200h
mov ds, ax
mov bx, 0
mov cx, 3fh
s: mov dl,[bx]
inc bx
loop s
mov ax, 4c00h
int 21
codesg ends
end
//2020年08月16日 06时29分31秒
assume cs:codesg
codesg segment
dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h
start: mov bx, 0
mov ax, 0
mov cx, 8
s: add ax,cs:[bx]
add bx, 2
loop s
mov ax, 4c00h
int 21
codesg ends
end start
assume cs:code, ds:data, ss:stack
data segment
dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h
data ends
stack segment
dw 0, 0, 0, 0, 0, 0, 0, 0
stack ends
code segment
start: mov ax, stack
mov ss, ax
mov sp, 16
mov ax, data
mov ds, ax
push ds:[0]
push ds:[2]
pop ds:[2]
pop ds:[0]
mov ax, 4c00h
int 21
code ends
end start
assume cs:code, ds:data, ss:stack
code segment
start: mov ax, stack
mov ss, ax
mov sp, 16
mov ax, data
mov ds, ax
push ds:[0]
push ds:[2]
pop ds:[2]
pop ds:[0]
mov ax, 4c00h
int 21
code ends
data segment
dw 0123h, 0456h
data ends
stack segment
dw 0, 0
stack ends
end start
;https://www.cnblogs.com/x54256/p/8109667.html
;编程:在屏幕中间显示当前的月份。
;分析:这个程序主要做两部分工作:
;(1)从CMOS RAM的8号单元读出当前月份的BCD码;要读取 CMOS RAM的信息,我们首先要向地址端口70h写入要访问的单元的地址:
;mov al,8
;out 70h,al
;然后从数据端口71h中取得指定单元中的数据:in al,71h
;(2)将用BCD码表示的月份以十进制的形式显示到屏幕上。
;我们可以看出 ,BCD 码值=十进制数码值,则BCD码值+30h=十进制数对应的ASCII码。
;从CMOS RAM的8号单元读出的一个字节中,包含了用两个 BCD 码表示的两位十进制数,高4位的 BCD码表示十位,低 4位的 BCD码表示个位。
;比如:00010100b表示14。
assume cs:code
code segment
start: mov al,8
out 70h,al ; 从地址端口70h,写入要访问的内存单元的地址
in al,71h ; 从数据端口71h,获取第8号内存单元(月)的数据
mov ah,al ; 将月的值赋给ah
mov cl,4 ; 右移4次
shr ah,cl ; 获取月份十位数的值(因为要把每一位数+30h)
and al, 00001111b ; 获取月份十位数的值
add ah,30h
add al,30h ; BCD码 ==> ASCII码
mov bx,0b800H ; 定位到显存的位置
mov ds,bx ; 我也不知道要写啥
mov byte ptr ds:[160*12+40*2],ah
mov byte ptr ds:[160*12+40*2+2],al
mov ax,4c00h
int 21h
code ends
end start
;2020年08月16日 14时43分53秒
;http://blog.sina.com.cn/s/blog_171daf8e00102xcwt.html
检测点14.1
(1)编程,读取CMOS RAM的2号单元内容。
assume cs:code
code segment
start: mov al,2 ; (al)=2 2号单元
out 70h,al ;将al送入端口70h,选中2号单元
in al,71h ;从端口71h处读出2号单元内容,送入al
mov ax,4c00h
int 21h
code ends
end start
(2)编程,向CMOS RAM的2号单元写入0。
assume cs:code
code segment
start: mov al, 2 ;(al)=2 2号单元
out 70h, al ;将al送入端口70h,选中2号单元
mov al, 0 ;(al)=0 写入端口的内容
out 71h, al ;将(al)=0写入到71h端口的2号单元内。
mov ax,4c00h
int 21h
code ends
end start
总结:使用debug测试时。我们发现in和out指令都不支持单步中断。
检测点14.2
编程,用加法和移位指令计算(ax)=(ax)*10
提示:(ax)*10=(ax)*2+(ax)*8
程序分析:
按照提示:(ax)*2左移1位;(ax)*8左移3位,(ax)*8==(ax)*2^3将2者相加就ok了。中间必须使用个寄存器,例如bx吧。
assume cs:code
code segment
start: mov bx, ax ;bx用于计算2的3次方
shl ax, 1 ;(ax)左移1位,等价于(ax)*2
mov cl, 3 ;移动3位,因为shl和shr只认cl
shl bx, cl ;(bx)左移3位,等价于(ax)*2^3=(ax)*8
add ax, bx ;(ax)=(ax)*2+(ax)*8=(ax)*10
mov 4c00H
int 21H
code ends
end start
总结:
逻辑移位是针对于二进制数据的位数移动,对应于十进制就是模数是2数据,一切都是围绕着模数是2或2的指数来计算的。它不特指针对于其他数据,例如3、7、9等。
此程序中ax并没有赋值。调试中可以将值赋值给ax,例如加入mov ax, 数值。
在测试中要考虑(ax)*10是否产生溢出,导致测试数据不正常。
; 8086/8088 汇编语言程序设计 齐志儒 1994 p 3
; 2020年08月16日 19时35分15秒
assume cs:code, ds:data, ss:stack
data segment
data1 db 15h
data2 db 26h
RLT db 0
data ends
stack segment
dw 0, 0, 0, 0, 0, 0, 0, 0
stack ends
code segment
start: mov ax, data
mov ds, ax
mov al, data1
mov ah, data2
add al, ah
mov RLT, al
HLT
mov ax, 4c00h
int 21
code ends
end start
SECTION .data
EatMsg: db "Eat at Joe's!", 10
EatLen: equ $-EatMsg
SECTION .bss
SECTION .text
global _start
_start:
nop
mov eax, 4
mov ebx, 1
mov ecx, EatMsg
mov edx, EatLen
int 80h
mov eax, 1
mov ebx, 0
int 80h
/*
wannian07@wannian07-PC:~$ nasm -f elf64 -g -F stabs eatsyscall.asm -o eatsyscall.o
wannian07@wannian07-PC:~$ ld -o eatsyscall eatsyscall.o
wannian07@wannian07-PC:~$ ./eatsyscall
Eat at Joe’s!
*/