[Assembly] A variety of methods to clear the screen and print the string (.asm source code)

Project environment
  • Compilation environment: build a nasm2.8 compilation environment.
  • Mirror file: use winhex_18.2 to brush in the code.
  • Virtual machine: Bochs-2.4.5 is used .
Project software
operation result

Insert picture description here

Program source code-method one (.asm)
org 0x7c00

jmp start
    string db 'world',0
    passwrod db "23456",0
    

start:
	mov ax,0xb800
	mov es,ax
    mov bx , 0x0000
    mov ax , 0

    mov si , 0x7c03

    mov cx , 0x0000
    mov ds , cx

do: 
    cmp bx ,0x0AF0 ; 0AF0 H =  2800 循环 2800 次
    ja write
    ; bx bp si di
    ; si di 
    ; bx,bp 上下组合
	mov byte [es:bx],' '
    inc bx
	mov byte [es:bx],0x0c
    inc bx

    jmp do

write:
    mov byte [es:bx],'h'
    inc bx
    mov byte [es:bx],0x0c
    inc bx
     
    mov byte [es:bx],'e'
    inc bx
    mov byte [es:bx],0x0c
    inc bx
     
    mov byte [es:bx],'l'
    inc bx
    mov byte [es:bx],0x0c
    inc bx
    
    mov byte [es:bx],'l'
    inc bx
    mov byte [es:bx],0x0c
    inc bx
    
    mov byte [es:bx],'o'
    inc bx
    mov byte [es:bx],0x0c
    inc bx

;    mov ax , 0
write2:

    mov cl , byte [ds:si]

    cmp cl , 0
    je exit


    mov byte [es:bx] , cl
    inc bx
    mov byte [es:bx] , 0x0c
    inc bx  
    inc si  
    inc ax  
    jmp write2


exit: jmp exit
Program source code-method two (.asm)
org 0x7c00  
jmp start  
    string db 'hello world',0  
start:  
    mov ax,0xb800  
    mov es,ax  
    mov bx , 0x0000  
    mov ax , 0  
    mov si , 0x7c03  
    mov cx , 0x0000  
    mov ds , cx  
do: ;清屏  
    cmp bx ,0x0AF0  
    ja  printstr  
    mov byte [es:bx],' '  
    inc bx  
    mov byte [es:bx],0x0c  
    inc bx  
    jmp do  
printstr:;输出字符串  
    mov cl , byte [ds:si]  
    cmp cl , 0  
    je exit  
    mov byte [es:bx] , cl  
    inc bx  
    mov byte [es:bx] , 0x0c  
    inc bx    
    inc si  
    jmp printstr  
exit: jmp exit

Guess you like

Origin blog.csdn.net/Gyangxixi/article/details/113612418