Start from scratch, boot02 (convert the print string function into a function)

Source: Internet
Author: User

Bind the function of printing strings on the screen as a function. For future use.
; Helloworld. ASM

Org 07c00h
; Setup stack. Setup stack at most top of 640 K
Start: mov ax, 0x0fc0
MoV SS, ax
MoV ax, 0x0400
MoV sp, ax

MoV BX, msg1
Push BX
Call dumpstr
Pop BX
JMP $

Dumpstr:
; Backup used registor
PUSH AX
Push BX
Push CX
Push DX
Push BP

; Get Parameter
MoV bp, SP
Add bp, 12
MoV BX, [BP]
; Calculator String Length
Xor cx, CX
Strlop: mov ax, [BX]
CMP ax, 0x0
JZ calend
INC CX
INC BX
JMP strlop
Calend:
Push CX

MoV ah, 0x03
Xor bh, BH
Int 0x10
 
Pop CX
MoV BX, 0x0007
Push BP
MoV bp, [BP]
MoV ax, 0x1301
Int 0x10
Pop BP

; Restore registor
Pop BP
Pop DX
Pop CX
Pop BX
Pop ax
RET
Msg1: dB 13, 10
DB 'Hello world'
DB 13, 10, 13, 10

Times 510-($-$) db 0
DW 0aa55h

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.