Wang Shuang-Course Design of assembly language 2

Source: Internet
Author: User

Assume Cs: Code
Code segment
Start0: mov BX, 0
MoV ax, 200 h
MoV es, ax

MoV ah, 2
MoV Al, 3
MoV CH, 0
MoV Cl, 2
MoV DH, 0
MoV DL, 0

INT 13 H

MoV ax, 200 h
PUSH AX
MoV ax, 0
PUSH AX
Retf

Start1: JMP short start

S1 dB '1. restart pc', 0, '2. start System ', 0, '3. clock ', 0, '4. set clock ', 0, '5. input error! ',' $ ', 0

Start: mov ax, 0b800h
MoV es, ax

MoV ax, CS
MoV ds, ax
MoV Si, 2

MoV DH, 10
MoV DL, 40
MoV BL, 160
MoV BH, 0

S: mov Al, DS: [Si]
CMP Al, 0
JNE s_next
INC DH
MoV DL, 39
INC BH
Cmp bh, 4
Je s_end

S_next: Push DX
PUSH AX
MoV Al, DH
Mul BL
MoV DH, 0
Add ax, DX
Add ax, DX
MoV Di, ax
Pop ax
Pop DX

MoV ES: [di], Al
INC Si
INC DL
JMP s

S_end: mov ah, 0
Int 16 h

CMP Al, '1'
JNE choice2
MoV ax, 0 ffffh
PUSH AX
MoV ax, 0
PUSH AX
Retf
; Jmp dword 0 FFFF: 0

Choice2: CMP Al, '2' second subroutine
JNE choice3

Call CLS

MoV ax, 0
MoV es, ax
MoV BX, 7c00h

MoV ah, 2
MoV Al, 1
MoV CH, 0
MoV Cl, 1
MoV DH, 0
MoV DL, 80 h

INT 13 H

MoV ax, 7c0h
PUSH AX
MoV ax, 0
PUSH AX
Retf
 
Choice3: CMP Al, '3' the third subroutine
JNE choice4

Call CLS
MoV BH, 7

Showtimecon: Call show_time
MoV ah, 0
Int 16 h

CMP ah, 1 h; key ESC
Je show_time_exit

CMP ah, 3bh; key F1
JNE showtimecon

INC BH
JMP showtimecon
 
Show_time_exit: Call CLS
JMP start1

Choice4: CMP Al, '4'' fourth subroutine set_time
JNE choice_other
JMP set_time

Choice_other: JMP start1

Set_time: Call getstr
JMP start1


Show_time: JMP showtime_start 'display The Time Function
Show_time_s1 dB
Showtime_start: PUSH AX
; Push BX
Push CX
Push DX
PUSH DS
Push es
Push Si
Push di

Show: mov ax, CS
MoV ds, ax
MoV Di, offset show_time_s1-offset start1

MoV ax, 0b800h
MoV es, ax
MoV Si, 12*160 + 10*2

MoV ax, 0

MoV CX, 6

Main_s: mov DL, [di]
Call r_fun
INC di

MoV byte ptr es: [Si], ah
MoV byte ptr es: [Si + 1], BH
MoV byte ptr es: [Si + 2], Al
MoV byte ptr es: [Si + 3], BH

Add Si, 4

Cmp cx, 4
JNA main_s1

MoV Al ,'/'
MoV ES: [Si], Al
MoV ES: [Si + 1], BH
Add Si, 2
Loop main_s

JMP short main_s3

Main_s1: cmp cx, 4
JB main_s2

Add Si, 8
Loop main_s

JMP short main_s3

Main_s2: cmp cx, 1
Je main_s3

MoV Al ,':'
MoV ES: [Si], Al
MoV ES: [Si + 1], BH

Add Si, 2
Loop main_s

JMP short main_s3

Main_s3: Pop di
Pop Si
Pop es
Pop DS
Pop DX
Pop CX
; Pop BX
Pop ax
RET

; Read data from CMOS RAM

R_fun: Push BX
Push CX
Push DX
Push Si

MoV Al, DL
Out 70 h, Al
In Al, 71 h

MoV ah, Al
MoV cl, 4
SHR ah, Cl
And Al, 1271111b

Add ah, 30 h
Add Al, 30 h

Pop Si
Pop DX
Pop CX
Pop BX
RET

; Write data to CMOS RAM
 
W_time: PUSH AX
Push BX
Push CX
Push DX
PUSH DS
Push es
Push di
Push Si

MoV BX, 0b800h
MoV ds, BX
MoV Si, 160*12 + 10*2

MoV Di, offset show_time_s1-offset start1
MoV ax, CS
MoV es, ax

MoV CX, 6
W_loop: mov DL, ES: [di]
CMP byte PTR [Si], '/'
Je w_loopcon
CMP byte PTR [Si], ':'
Je w_loopcon

Sub Si, 2

Cmp cx, 3
JNE w_loopcon

Add Si, 8

W_loopcon: Add Si, 2

MoV BH, [Si]
MoV BL, [Si + 2]
Call w_fun

Add Si, 4
INC di
Loop w_loop

Pop Si
Pop di
Pop es
Pop DS
Pop DX
Pop CX
Pop BX
Pop ax
RET

W_fun: PUSH AX
Push BX
Push CX
Push DX

Sub BH, 30 h
Sub BL, 30 h

MoV Al, BH

MoV cl, 4
SHL Al, Cl

And Al, 11111_ B
And BL, 1271111b

Or Al, BL

MoV DH, Al

MoV Al, DL; transport... CMOS address
Out 70 h, Al; write the CMOS address which will be visit to 70 h

W_wait: in Al, 71 h
MoV DL, Al

MoV Al, DH
Out 71 h, Al; DH deposit data which will be write to CMOS
Cmp dl, Al
JNE w_wait

Pop DX
Pop CX
Pop BX
Pop ax
RET

CLS: push ax 'screen clearing function
PUSH DS
Push Si
Push CX

MoV ax, 0b800h
MoV ds, ax
MoV Si, 0

MoV CX, 80*25
Cls_loop: mov byte PTR [Si],''
MoV byte PTR [Si + 1], 7;
Add Si, 2
Loop cls_loop

Pop CX
Pop Si
Pop DS
Pop ax
RET

Getstr: JMP getstrnext String Stack
Stack dB 50 DUP (0)

Getstrnext: mov BH, 7
Call show_time

PUSH AX
Push Si
Push DX
Push BX

MoV Si, offset stack-offset start1
MoV ax, CS
MoV ds, ax

MoV DH, 12
MoV DL, 10

Getstrs: mov ah, 0
Int 16 h

CMP Al, 30 h
JB nochar
CMP Al, 39 h
Ja nochar

MoV ah, 0
Call charstack
MoV ah, 2
Call charstack
JMP getstrs

Nochar: CMP ah, 0eh
Je backspace
CMP ah, 1ch
Je enter
JMP getstrs

Backspace: mov ah, 1
Call charstack
MoV ah, 2
Call charstack
JMP getstrs

Enter: Push CX

MoV CX, 1
MoV Al, 0
MoV ah, 0
Call charstack

MoV CX ,'@'
MoV ah, 2
Call charstack

Call w_time
Call CLS

Pop CX

Pop BX
Pop DX
Pop Si
Pop ax
RET

Charstack: JMP short charstart
Table DW charpush-start1, charpop-start1, charshow-start1
Top DW 0

Charstart: Push BX
Push DX
Push di
Push es

CMP ah, 2
Ja charstackend
MoV BL, ah
MoV BH, 0
Add Bx, BX
MoV Di, Offset Table-offset start1
JMP word PTR [BX] [di]

Charstackend: JMP sret

Charpush: mov BX, top-1fh
MoV [Si] [BX], Al
INC top-1fh
JMP sret

Charpop: CMP top-1fh, 0
Je sret
Dec top-1fh
MoV BX, top-1fh
MoV Al, [Si] [BX]
JMP sret

Charshow: mov BX, 0b800h
MoV es, BX
MoV Al 160
MoV ah, 0
Mul DH
MoV Di, ax
Add DL, DL
MoV DH, 0
Add Di, DX

MoV BX, 0

Charshows: cmp bx, top-1fh
JNE noempty
; MoV byte ptr es: [di],''
JMP sret
 
Noempty: mov Al, [Si] [BX]
MoV ES: [di], Al

CMP byte ptr es: [di + 2], '/'
Je charshownext
CMP byte ptr es: [di + 2], ':'
Je charshownext
; CMP byte ptr es: [di + 2],''
; Je charshownext

Sub Di, 2

Cmp cx ,'@'
JNE charshownext
MoV byte PTR [Si] [BX], 0
MoV byte PTR top-1fh, 0

Charshownext: Add Di, 2

MoV byte ptr es: [di + 2],''
INC BX
Cmp bx, 0ch
Je sret
Cmp bx, 6
JNE charshowcon
Add Di, 8

Charshowcon: Add Di, 2
JMP charshows

Sret: Pop es
Pop di
Pop DX
Pop BX
RET

Start2: mov BX, offset start0' code copy
MoV ax, CS
MoV es, ax

MoV ah, 3
MoV Al, 1
MoV CH, 0
MoV Cl, 1
MoV DH, 0
MoV DL, 0 h

INT 13 H

MoV BX, offset start1
MoV ax, CS
MoV es, ax

MoV ah, 3
MoV Al, 4
MoV CH, 0
MoV Cl, 2
MoV DH, 0
MoV DL, 0

INT 13 H

MoV ax, 4c00h
Int 21 h
Code ends
End start2

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.