CS344-321 Assembly Language Programming

Download Report

Transcript CS344-321 Assembly Language Programming

CS344-321 Assembly Language Programming
Period 11
Directive
- EQU
- GROUP
- .DATA
- .STACK
ตัวอย่าง 3.4 .com
page ,80
title Hello World Program
; This program displays "Hello, world!"
dosseg
.model tiny
.code
org 100h
start:
mov ah,9
mov dx,offset hello_message
int 21h
mov ax,4c00h
int 21h
hello_message db 'Hello, world!', 0dh, 0ah, '$’
end start
ตัวอย่าง 3.5 .exe (small model)
dosseg
.model small
.stack 100h
.data
hello_message db 'Hello, world!', 0dh, 0ah, '$'
.code
main:
mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset hello_message
int 21h
mov ax,4c00h
int 21h
end main
ตัวอย่าง แสดงให้ เห็นว่า ข้ อมูลกับคาสัง่ เรี ยงอย่างไรก็ได้ ขึ ้นอยู่กบั ความต้ องการของผู้เขียน
dosseg
.model tiny
.code
org 100h
start: jmp l
hello_message db 'Hello, world!', 0dh, 0ah, '$’
l: mov ah,9
mov dx,offset hello_message
int 21h
mov ax,4c00h
int 21h
end start
หมายเหตุ โปรแกรมไวรัสสำหรับ .com ทำได้โดยกำรเขียนส่วนที่เป็ นไวรัสไว้หน้ำโปรแกรม แล้วกระโดดไปทำงำน
ของโปรแกรมเดิม
กระโดดไปทำงำนที่ไวรัสก่อน ส่วนโปรแกรม
สำหรับ .exe ต้องแก้จุดเริ่ มต้นของโปรแกรมใน header ของแฟ้ ม .exe ให้
ตัวอย่าง แสดงให้ เห็นว่า โปรแกรม ตามแนวคิดของ John Von Newman ประกอบด้ วยข้ อมูลกับคาสัง่
ถ้ าเรารู้รหัสคาสัง่ เราสามารถเขียนคาสัง่ ภาษาเครื่ องโดยตรงได้
dosseg
.model tiny
.code
org 100h
start: jmp l
hello_message db 'Hello, world!', 0dh, 0ah, '$’
l: db 0B4h,09h
;mov ah,9
mov dx,offset hello_message
int 21h
mov ax,4c00h
int 21h
end start