Assembly language uses escape characters for simple "full-screen" text output

Source: Internet
Author: User

This is a simple assembler running under Linux, using NASM 2.11, which shows a simple "full screen" text output using escape characters

;executable file name: Eatterm;Version: 1.0;Date Created: 7/10/2016;Last updated on: 7/10/2016;Author: Moonlight Poet;Description: A simple assembler running under Linux, using NASM 2.11,;demonstrates simple "full-screen" text output with escape characters; ;use the following command to generate:;Nams-f elf-g-F stabs eatterm.asm;ld-o eatterm EATTERM.O;Section. Data;contains initialized dataScrwidth:Equ the        ;By default We assume a 80-character widthPosterm:Db -,"[01;01h"    ;<esc>[<y>;<x>hPoslen:Equ $-posterm;length of the term position stringClearterm:Db -,"[2J"        ;<esc>[2jClearlen:Equ $-clearterm;length of the purge stringadmsg:Db"Eat at Joe ' s!"    ;Advertising MessagesAdlen:Equ $-admsg;the length of the ad messagePrompt:Db"Press Enter:"    ;User tip InformationPromptlen:Equ $-prompt;Length of user tip information;This table provides us with a two-bit ASCII bit (digit) for numbers between 0 and 80. ;we do not generate ASCII numbers in the insertion terminal control string by calculation,;Instead, they are looked up in a table and two ASCII bits are removed to a 16-bit register at a time, such as DX,;then set the value of the register to the appropriate location of the anti-theft terminal control string posterm. See Gotoxy. ;If you intend to work on a larger, more than 80x80 console,;additional ASCII bit encodings must be added to the digits. ;Note: The code shown here only works on the console of the maximum 99*99. Digits:Db"0001020304050607080910111213141516171819"DB"2021222324252627282930313233343536373839"DB"4041424344454647484950515253545556575859"DB"6061626364656667686970717273747576777879"Section . BSS;contains uninitialized dataSection . Text;segments that contain code;----------------------------------------------------------------------------------------------------;CLRSCR: Emptying the Linux console;Last updated on: 7/10/2016;input parameters: None;return value: None;Modified: None;Call: Kernel sys_write;Description: Sends a predetermined control string <esc>[2j to the console, which empties the entire displayCLRSCR:    PushRax;Saving relevant registers    PushRBXPushRCXPushRDXmovEcx,clearterm;offset address of the delivery terminal control string    movEdx,clearlen;length of the delivery terminal control string    PagerWritestr;send Terminal control string to console    PopRdx;Recover relevant registers    PopRCXPopRBXPopRaxret;----------------------------------------------------------------------------------------------------;gotoxy: Position the Linux control cursor at (x, y) coordinates;Last updated on: 7/10/2016;input parameters: X Storage to ah,y storage to AL;return value: No;modified: Posterm terminal Control sequence string;Call: Kernel sys_write;Description: Prepares a terminal control string for x, y coordinates passed to Al and Ah;and call Sys_write to position the console cursor to the (x, y) position;after calling Gotoxy, writing text to the console displays the text starting at the (x, y) position. Gotoxy:    PushRbx;Save the Register of the keynote program    PushRCXPushRDXXOREbx,ebx;Qing 0 ebx    XOREcx,ecx;ECX Register Operation ibid .;number to insert Y    movBl,al;Place the value of Y in the scale term EBX register    movCx,word [digits+ebx*2];Take out the decimal number and put it in the CX register    movWord [posterm+2],cx;inserting a number into the control string;number of x inserted    movBl,ah;Place the value of x in the scale term EBX register    movCx,word [digits+ebx*2];Take out the decimal number and put it in the CX register    movWord [posterm+5],cx;inserting a number into the control string;send control sequence to standard output    movEcx,posterm;address of the delivery control string    movEdx,poslen;passing the length of the control string    PagerWritestr;sending a control string to the console;to mop up and return:    PopRDXPopRCXPopRaxret;----------------------------------------------------------------------------------------------------;writectr: Send a string to the central location of a 80-string-wide Linux console;Last updated on: 7/10/2016;input Parameters: Pass Y value to Al, string address to ecx, string length to EdX;return value: None;modified: Posterm terminal Control sequence string;Call: Gotoxy, Writestr;Description: Displays a string in the middle of a 80-column-wide Linux console display area;calculates x for the length of the passed-in string,;then call Gotoxy and Writestr to send the string to the consolewritectr:    PushRBXXOREBX,EBXmovBl,scrwidthSubBL,DLSHRBl1    movAH,BLPagerGotoxyPagerWritestrPopRBXret;----------------------------------------------------------------------------------------------------;writestr: Send a string to the Linux console;Last updated on: 7/10/2016;input Parameters: Pass string address to ECX, string length to EdX;return value: None;Modified: None;Call: Kernel sys_write;Description: Displays a string to the Linux console via a sys_write kernel call;Writestr:    PushRax;Save the relevant registers    PushRBXmoveax4    ;Specifies the Sys_write call    movEbx1    ;Specify file Descriptor 1: Standard output    int70G;making kernel calls    PopRbx;Recover related Registers    PopRaxret        ;returnGlobal _start;the connector needs this to find the entry point._start:    NOP        ;This no-action command makes gdb feel very happy .    ;First we empty the terminal display    PagerCLRSCRmovAl A    movecx,admsgmovEdx,adlenPagerwritectrmovax,0117hPagerGotoxymovecx,promptmovEdx,promptlenPagerWritestrmoveax3    movEbx0    int80hExit:    moveax1    movEbx0    int70G

Effect:

Assembly language uses escape characters for simple "full-screen" text output

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.