Skip to content

Commit

Permalink
更新:量子力学、汇编程序设计基础 (QSCTech#61)
Browse files Browse the repository at this point in the history
* Add files via upload

* Add files via upload
  • Loading branch information
h-alz authored and Zhang Hai committed Jan 16, 2019
1 parent c5e9b41 commit 7700702
Show file tree
Hide file tree
Showing 50 changed files with 792 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
104 changes: 104 additions & 0 deletions 汇编语言程序设计基础/Homework/HW01/HW1_3160______.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
ASSUME CS:CODE, DS:DATA
;define the data segment
DATA SEGMENT
GREEN_HIGH DB 0
GREEN_LOW DB 0
BLUE_H DB 0
BLUE_M DB 0
BLUE_L DB 0
HIGH_PART DW 0
LOW_PART DW 0
NUM DB 0
DATA ENDS
;the main code
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
;the address of the display buffer
MOV AX, 0B800H
MOV ES, AX
;initialize the loop condition
MOV NUM, 0
MOV LOW_PART, 0
;loop to print the ASCII table
OUT_LOOP:
MOV HIGH_PART, 0
IN_LOOP:
CALL CTRL_ROW_COL
CALL PRINT
ADD HIGH_PART, 160
INC NUM
MOV AH, 0
MOV AL, NUM
CMP AL, 0
; if NUM is 0, finish the program
JE FINISH
MOV BL, 25
; AL/25
DIV BL
CMP AH, 0
JNE IN_LOOP
ADD LOW_PART, 14
JMP OUT_LOOP
FINISH:
MOV AX, 4C00H
INT 21H

;print each item function
PRINT PROC
MOV AL, NUM
MOV AH, 12
MOV BX, HIGH_PART
MOV DI, LOW_PART
MOV ES:[BX + DI], AX
MOV AL, GREEN_HIGH
MOV AH, 10
MOV ES:[BX + DI + 2], AX
MOV AL, GREEN_LOW
MOV ES:[BX + DI + 4], AX
MOV AL, ' '
MOV ES:[BX + DI + 12], AX
RET
PRINT ENDP

;control the row and column information
;so that the ascii table is printed in 25 lines
CTRL_ROW_COL PROC
MOV AL, NUM
MOV AH, 0
MOV BL, 16
DIV BL
CMP AL, 10
JB PART_1
ADD AL, 7
PART_1:
ADD AL, '0'
MOV GREEN_HIGH, AL
CMP AH, 10
JB PART_2
ADD AH, 7
PART_2:
ADD AH, '0'
MOV GREEN_LOW, AH
MOV AL, NUM
MOV AH, 0
; AL/10
MOV BL, 10
DIV BL
ADD AH, '0'
MOV BLUE_L, AH
MOV AH, 0
DIV BL
ADD AH, '0'
MOV BLUE_M, AH
ADD AL, '0'
MOV BLUE_H, AL
RET
CTRL_ROW_COL ENDP
;the main code ends
CODE ENDS
END START



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
167 changes: 167 additions & 0 deletions 汇编语言程序设计基础/Homework/HW02/HW2_3160______.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
.model small
.386
.stack 200h
.data
num1 dw 0 ;整数1
num2 dw 0 ;整数2
product dd 0 ;乘积

buffer db 10 ;0ah缓冲区大小
k_size db ? ;实际读入字数的格式,中断调用后,自动填入
k_buffer db 10 dup(0) ;键盘输入最多10个字符
asc_arr db "0123456789ABCDEF" ;输出数字时,需要的ASC码
.code
.STARTUP
call get_int
mov num1, ax
call crlf
call get_int
mov num2, ax
;扩展到32寄存器,
;然后求乘积
movzx eax, num1
movzx ebx, num2
mul ebx
mov product, eax
call crlf
movzx eax, num1
mov ebx, 10
call print_int ;显示第2个整数
mov dl, '*'
call print_char
movzx eax, num2
mov ebx, 10
call print_int ;显示第2个整数
mov dl, '='
call print_char
;显示10进制乘积
call crlf
mov eax, product
mov ebx, 10
call print_int
;显示16进制乘积
call crlf
mov eax, product
mov ebx, 16
call print_int
mov dl, 'H'
call print_char
;显示2进制乘积
call crlf
mov eax, product
call print_bin
mov dl, 'B'
call print_char
.EXIT

;eax -整数
;ebx -进制
print_int proc

mov cx, 0 ;统计整数的位数
L_div:
mov edx, 0 ;除法之前edx清0
div ebx
push dx ;余数入栈
inc cx ;统计位数+1
cmp eax, 0 ;eax除尽
jne L_div
L_print:
pop si ;取出余数
mov dl, asc_arr[si]
mov ah, 2
int 21h
loop L_print

ret
print_int endp
;输入十进制字符串
;转换二进制,返回值ax
get_int proc

;0ah 键盘读入一个整数字符串
lea dx, buffer
mov ah,0ah
int 21h
mov ch,0
mov cl, k_size;
mov ax, 0 ; 整数初始0
lea si, k_buffer
mov dh, 0
mov bx, 10
L_read:
mul bx ;乘10
mov dl, [si]
sub dl, '0'
add ax, dx ;ax加上当前的数字
inc si
loop L_read

ret
get_int endp
;输出一个换行
crlf proc
push ax
push dx
mov dl, 0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h

pop dx
pop ax
ret
crlf endp
;显示一个整数的二进制
; eax - 整数
print_bin proc
mov cx, 8 ;8组
L1:
push cx
mov cx, 4 ;一次显示4位
L2:
shl eax, 1
jc is_1
mov dl, '0' ;0
call print_char
jmp L2_next
is_1:
mov dl, '1' ;1
call print_char
L2_next:
loop L2

mov dl, ' ' ;显示一个空格
call print_char

pop cx
loop L1

mov dl, 8 ;退格
call print_char
ret
print_bin endp
;显示dl里面的字符
print_char proc
push ax
mov ah, 2
int 21h
pop ax
ret
print_char endp
end
Loading

0 comments on commit 7700702

Please sign in to comment.