![]() | ภาษาแอสเซมบลี้ และ การแปล | ![]() |
ตัวอย่างการดู register ด้วยโปรแกรม debug C:\MASM611\BIN>debug -r AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=119B ES=119B SS=119B CS=119B IP=0100 NV UP EI PL NZ NA PO NC 119B:0100 C8 DB C8 -q C:\MASM611\BIN> |
|
วิธีติดตั้งตัวแปลภาษา Assembly
1. Compiler : masm611.zip 4.7 MB 2. คลาย zip ลงในเครื่อง 3. สั่ง run โปรแกรม setup.exe 4. กด Enter ประมาณ 20 ครั้ง - เมื่อ enter ที่ 12 ควรเปลี่ยน binr เป็น bin 5. ถ้าพบ Setup Successfully กด Ctrl-C ได้ 6. โปรแกรมทั้งหมดอยู่ในห้อง c:\masm611 7. พบตัวแปลภาษาใน c:\masm611\bin\ 8. ถ้าขณะ install ถ้าไม่เปลี่ยน bin เป็น binr - ต้อง cd c:\masm611\binr - ต้อง copy *.* c:\masm611\bin - จึงจะแปลโปรแกรมได้สำเร็จ ตามตัวอย่าง |
|
วิธีแปล (Compile) ลิงค์(Link) และสั่งประมวลผล(Execute)
|
1. แสดงการสร้างโปรแกรมใช้งาน interrupt
|
| C:\>debug test.com -a 11BD:0100 int 0h 11BD:0102 -rcx CX 0001 :2 -w Writing 00002 bytes -q C:\>test.com Your program caused a divide overflow error. If the problem persists, contact your program vendor. C:\>
2. แสดงการประมวลผลใน debug อย่างง่าย
|
| C:\>debug -a 100 0AE8:0100 mov ah,02 0AE8:0102 mov dl,51 0AE8:0104 int 21 0AE8:0106 shr dl,1 0AE8:0108 shl dl,1 0AE8:010A int 21 0AE8:010C int 20 0AE8:010E -g QP Program terminated normally -
3. แสดงใช้ directive segment ends แบบเก่า
|
|
; a1.asm compile by MASM611
cseg segment
assume cs:cseg,ds:cseg ; Code segment, Data segment
push cs
pop ds
jmp start ; กระโดดไป start label
msg1 db 'a',0dh,0ah,'$'
start: mov ah,09h ; พิมพ์ string ทางจอภาพ
lea dx,msg1
int 21h
mov ah,01h ; รับค่าจากแป้นพิมพ์
int 21h
jmp start
cseg ends ; ปิด segment
end ; เลิกการทำงาน
4. แสดงการทำซ้ำด้วย label, cmp, je
|
|
; Get char and repeat print char until e or E
.model small
.data
x1 db "type e or E to Exit",0ah,0dh,'$'
.code
pmain proc far ; can not change far to near
push ds ; 1 of 5 line required for end .exe
mov ax,0 ; 2 clear ax by xor ax,ax
push ax ; 3 send ax to stack
mov ax,@data
mov ds,ax
start: mov ah,09h ; พิมพ์ string ทางจอภาพ
lea dx,x1
int 21h
mov ah,06h ; รับ char จากแป้นพิมพ์ส่งเข้า al
top: mov dl,0ffh ; ถ้า dl เป็น ff จะรับค่าจาก console แบบไม่หยุดรอ
int 21h
jz typeo ; ถ้าไม่กดอะไร จะไป typeo เพราะ ah ค้างที่ 6 อยู่
mov cl,al ; เก็บตัวอักษรใน al ไว้กลัวหาย
cmp al,'E'
je finish
cmp al,'e'
je finish
typeo: mov dl,cl ; ถ้า dl ไม่เป็น ff จะส่งค่าใน al ไป console
int 21h
jmp top
finish: ret ; ไม่สามารถใช้ int20 เพื่อสั่งให้เลิกงาน
pmain endp
.stack 200h ; not required
end pmain
5. แสดงการเขียน macro
|
|
setproc macro
push ds ; 1 of 5 line required for end .exe
mov ax,0 ; 2 clear ax by xor ax,ax
push ax ; 3 send ax to stack
mov ax,@data
mov ds,ax
endm
prtout macro
mov ah,09h
lea dx,msg
int 21h
endm
; =============
; Main program
; =============
.model small
.data
msg db 'This is the program testing $'
.code
pmain proc far ; can not change far to near
setproc
prtout
ret
pmain endp
.stack 200h ; not required
end pmain
|
|
|
|
|