, Nasm "" - ".text", ".data" ".bss" ( , ). "." . , , "", "", . , .programData is going to be read-only. Since you don't try to write to it this isn't going to do any harm... but.data` .
asm Linux, , . , - . - "andlinux" ( ), Linux- Windows. Linux " ". Linux.
DOS DosBox... " DOS" . " " B800h: xxxx. ( "character" "color" ). " ", , . . !
, , , . "msg" "len", , - . , - , . , (printf does, sys_write ) , edx. , int 80h vs int 21h vs WriteFile. , ...
EDIT: , . , call ( ) , ret , , ss:sp . , , , ret.
; purpose: to demonstrate a subroutine
; assemble with: nasm -f bin -o myfile.com myfile.asm
; (for DOS)
; Nasm defaults to 16-bit code in "-f bin" mode
; but it won't hurt to make it clear
bits 16
; this does not "cause" our code to be loaded
; at 100h (256 decimal), but informs Nasm that
; this is where DOS will load a .com file
; (needed to calculate the address of "msg", etc.)
org 100h
; we can put our data after the code
; or we can jump over it
; we do not want to execute it!
; this will cause Nasm to move it after the code
section .data
msg db "Hello, World!", 13, 10, "$"
msg2 db "Goodbye cruel world!", 13, 10, "$"
section .text
; execution starts here
mov dx, msg ; address/offset of msg
call myprint
; "ret" comes back here
; no point in a subroutine if we're only going to do it once
mov dx, msg2
call myprint
; when we get back, do something intelligent
exit:
mov ah. 4Ch ; DOS exit subfunction
int 21h
;
; subroutines go here, after the exit
; we don't want to "fall through" into 'em!
myprint:
; expects: address of a $-terminated string in dx
; returns: nothing
push ax ; don't really need to do this
mov ah, 9 ; DOS print subfunction
int 21h ; do it
pop ax ; restore caller ax - and our stack!
ret
; end of subroutine
, , "". - , dx. Linux ( ). ...