[Assembly] Assembly language implementation of a simple text editor (cursor movement, roll up and backspace delete)

Source: Internet
Author: User

A simple text editor implemented by the assembler, with detailed comments in the code.

Ideas and Details:

(1) In the center of the screen to initialize a piece of area, and positioning the cursor, the use of No. 16th Interrupt No. 0 function is stored in the Ah,al Scan code and ASCII code, thus the function key judgment.

(2) To achieve the operation of the cursor, through the change of the DH,DL and number 10th interrupt 2nd function of the cursor settings, the upper and lower left and right to change the value of DH,DL respectively.

(3) The operation of the backspace is to move the cursor to the left, and then use the number 21st interrupt output space can be deleted.

(4) When the lower bound exceeds a specified value, a volume is rolled up, and the current cursor position is shifted above.

(5) Pay attention to the processing of the border, left to the beginning of the line to move the Welt, right to the end of the row to move down, moving up and down the attention boundary, backspace to a row of rows up and down, the process of outputting characters

More than width wrap, these are the details to be dealt with.

(6) Pay attention to the protection of DX and AX values (pressed into the stack)



;  by Tachdata segment Esc_key equ 1bh; exit Win_ulc equ 30; left column WIN_ULR equ 8; upstream WIN_LRC equ 50; right column WIN_LRR   Equ 16, downlink win_width equ 20, Width board_shift equ 48h, cursor up board_down equ 50h; cursor down board_left equ 4Bh    Cursor left board_right equ 4Dh; cursor right shift board_back equ 08h; BACKSPACE string db "Tach ' notepad!$" endsstack segment DW-DUP (0) Endscode Segmentstart:;     Set segment Registers:mov ax, data mov ds, ax mov es, ax;----------output title------------------mov ah,2 MOV dh,win_ulr-1 mov dl,win_ulc+2 mov bh,0 int 10h Lea DX, string mov ah, 9 int 21h; Output string at DS:DX;-------------------------------------Locate:-----Set cursor initial position-----------mov ah,2 mov dh,w IN_ULR mov dl,win_ulc push DX mov bh,0 int 10h;--------------------------------;----Initialization screen---------- --------mov ah,6 mov ch,win_ulr mov cl,win_ulc mov dh,win_lrr mov DL,WIN_LRC mov bh,0f4h, white red character int 10h pop dx,----------------------------get_char:mov ah,0; 16h No. 0 function, ah mid-scan code, AL in ASC  II yards int 16h cmp al,0; if function key then al=0 JE K;-----Use ASCII code to judge-----------------------cmp Al,esc_key JE Exit CMP al,0dh JE Enter cmp al,board_back JE back;---read the current cursor position---------------mov ah,3 mov bh, 0 int 10h;---------------------push dx; protect variable cmp DL,WIN_LRC; Enter characters over right column value Jge NK jmp N nk:i NC DH mov dl,win_ulc push dx;--------------------mov bh,0; reset the cursor position mov ah,2 int 10h;-------------     ------n:cmp DH,WIN_LRR Jge roll; whether to cross the nether, roll Next:mov dl,al; output input characters mov ah,2 int 21h Pop DX    JMP Get_char;-------the processing of function keys (scan codes)---------------k:cmp ah,board_shift JZ shift CMP Ah,board_down Je Down cmp ah,board_left JE Left cmp ah,board_right je right jmp Get_char;-------------rolled up a row--------- ------------Roll:moV ah,6 push AX mov al,1 mov ch,win_ulr mov cl,win_ulc mov dh,win_lrr mov DL,WIN_LRC mov bh,0f4h i     NT 10h pop ax pop dx cmp dh,win_lrr jbe KK Dec dh kk:dec dh; After the roll up, DH with the self-reduction mov bh,0 mov ah,2 int 10h push DX jmp Next------------------------------------------handle line break--------------------en Ter:mov ah,3 mov bh,0 int 10h inc DH mov DL,WIN_ULC mov bh,0 mov ah,2 int 10h jmp Get_char ;-----------------------------------------cursor up-----------------------shift:mov ah,3 mov bh,0 int 10h Dec DH CMP dh,win_ulr jge S inc DH S:mov bh,0 mov ah,2 int 10h jmp get_char;------------cursor down------- -----------------Down:mov ah,3 mov bh,0 int 10h inc DH CMP dh,win_lrr jbe D Dec dh d:mov BH, 0 mov ah,2 int 10h jmp Get_char;-------------------------------------------------cursor left--------------------l Eft:mov ah,3 movbh,0 int 10h Dec DL cmp DL,WIN_ULC jge L inc DL Dec DH CMP dh,win_ulr jge L inc DH L:mov      bh,0 mov ah,2 int 10h jmp Get_char,-----------------------------;------------cursor to the right-----------------: MOV ah,3 mov bh,0 int 10h inc DL CMP DL,WIN_LRC JBE R Dec DL inc DH CMP DH,WIN_LRR Jbe R D EC DH R:mov bh,0 mov ah,2 int 10h jmp get_char;-------------------------;---------backspace key---------------BA Ck:mov ah,3 mov bh,0 int 10h Dec DL cmp dl,win_ulc jge B mov dl,win_lrc Dec DH cmp dh,     WIN_ULR Jge B inc DH B:mov bh,0 mov ah,2 int 10h push DX mov dl,20h mov ah,2 int 21h    Pop DX mov bh,0 mov ah,2 int 10h jmp Get_char;-----------Exit program------------------------exit: mov ax, 4c00h;    Exit to operating system. int 21h endsend start; Set entry point and stop the assembler.


[Assembly] Assembly language implementation of a simple text editor (cursor movement, roll up and backspace delete)

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.