assume cs:codesg
datasg segment
;string
db 'My name is YangKunLong.', 0
;160--the bytes per line, help to calculate -----and color for display
db 160,01000010B
;start at ds:[26], to storage the temp variable of the divdw.
dw 8 dup (0)
datasg ends
stacksg segment
dw 16 dup (0)
stacksg ends
codesg segment
main: mov ax, datasg
mov ds, ax
mov ax, stacksg
mov ss, ax
mov sp, 16
mov ax, 0B800h
mov es, ax
mov si, 0
mov dh, 8
mov dl, 3
mov ch, 0
mov cl, ds:[25]
call show_str
mov ax, 4240H
mov dx, 000FH
mov cx, 0AH
call divdw
mov ax, 4c00h
int 21h
;;function : cannot overflow div
;; dx -- higher 16bit of dividend ax- lower 16bit of dividend cx -- divisor
;;return dx -- higher 16 bit of result ax -- lower 16bit of result cx --remainder
divdw:
push bx
mov ds:[26], ax
mov ds:[28], dx
mov ds:[30], cx
;; H/N
mov ax, dx
mov dx, 0
div cx
mov ds:[32], ax ;int(H/N)
mov ds:[34], dx ;rem(H/N)
;storage (int)H/N * 65536
;mov ds:[36], 0000H
mov ds:[38], ax
;calc (rem)H/N *65536
mov dx, ds:[34]
mov ax, 0
;(rem)H/N * 65536 + L
add ax, ds:[26]
;((rem)H/N * 65536 + L)/N
div cx
mov cx, dx ;存余数
;两项相加
mov dx, ds:[38]
add ax, ds:[36] ; +0 可以不做
pop bx
ret
;;function : show a string with 0 ended at certain position and color
;;dh--line no. dl--column no.
;;cl--color ds:si--the beginning of the string
;;return none
show_str:
push bx
push si
push ax
push cx
;;calculate the first address of the string in video memory
mov al, dh
mul byte ptr ds:[24]
mov bx, ax
add bx, si
add bx, si
mov ah, 0
mov al, dl
add bx, ax
add bx, ax
change:
mov cl, [si]
mov ch, 0
jcxz ok
mov es:[bx], cl
pop cx
mov byte ptr es:[bx+1], cl
push cx
inc si
inc bx
inc bx
jmp short change
ok: pop cx
pop ax
pop si
pop bx
ret
codesg ends
end main
- [游客] 如果不加ds:就是相当于一下的语句 mov al,16 mov al,17 mov al,18 10/31 00:12
- [chinatree] 编译器不错,支持@@了。当然程序也不错。 10/15 01:48
- [hitlerdsaf] 中间跳转的时候二级跳了,提示jump out of range ,我晕倒。二级跳显得非常不好看。唉 10/12 18:40
- [chinatree] 作业类型有编辑文章的功能,你可以修改下。 09/30 20:15
- [hitlerdsaf] 6、1 1 2 2 4 7、512 256 第6、7题答案更正 09/30 17:28
- [hitlerdsaf] MOV AL 02H ADD AL, AL ADD AL, AL ADD AL, AL 09/29 15:26
- [chinatree] 全对。 09/29 15:23