PAGE 60, 132
TITLE ADDS 5 BYTES OF DATA
STSEG SEGMENT
DB 32 DUP ( ? )
STSEG ENDS
DTSEG SEGMENT
DATA_IN DB 25H, 12H, 15H, 2BF, 1FH
SUM DB ?
DTSEG ENDS
CDSEG SEGMENT
MAIN PROC FAR
ASSUME CS: CDSEG, DS: DTSEG, SS: STSEG
MOV AX, DTSEG
MOV DS, AX
MOV CX, 05
MOV OFFSET DATA_IN
MOV AL, 0
AGAIN: ADD AL, [BX]
INC BX
DEC CX
JNZ AGAIN
MOV SUM, AL
MOV AH, 4CL
INT 21H
MAIN ENDP
CDSEG ENDS
END MAN
ولی کامپایل نمیشه.سلامیونس جان اول اینکه چرا وبلاگت را پروندی؟!!!!!!!!!!!
خوبی رفیق...
کتاب مزیدی برنامه هاش رو جوری نوشته که قابل کامپایل با نرم افزار masm هستن
شما باید برای نوشتن برنامه هایی که هم توی ویندوز استفاده بشن هم تو لینوکس کاری به وقفه های داس نداشته باشی یا از توابع سیستمی لینوکس استفاده نکنی باید بجای این کارا مستقیما با حافظه و پورت های سخت افزاری کار کنی و برای نوشتن برنامه از nasm استفاده کنی که هر دو جا می تونه برات کامپایل کنه و syntax هم مطابق استاندارد AT&T می باشد...
Therefore, it would make sense to become at least passingly familiar with the AT&T mnemonic set. There are some general rules that, once digested, make it much easier. Here's the list in short form:
*
AT&T mnemonics and register names are invariably in lowercase. This is in keeping with the Unix convention of case sensitivity, and at complete variance with the Intel convention of uppercase for assembly language source. I've mixed uppercase and lowercase in the text and examples to get you used to seeing assembly source both ways, but you have to remember that while Intel (and hence NASM) suggests uppercase but will accept lowercase, AT&T requires lowercase.
*
Register names are always preceded by the percent symbol, %. That is, what Intel would write as AX or EBX, AT&T would write as %ax and %ebx. This helps the assembler recognize register names.
*
Every AT&T machine instruction mnemonic that has operands has a single-character suffix indicating how large its operands are. The suffix letters are b, w, and l, indicating byte (8 bits), word (16 bits), or long (32 bits). What Intel would write as MOV BX,AX, AT&T would write as movw %ax,%bx. (The changed order of %ax and %bx is not an error. See the next rule!)
*
In the AT&T syntax, source and destination operands are placed in the opposite order from Intel syntax. That is, what Intel would write as MOV BX,AX, AT&T would write as movw %ax,%bx. In other words, in AT&T syntax, the source operand comes first, followed by the destination. This actually makes a little more sense than Intel conventions, but confusion and errors are inevitable.
*
In the AT&T syntax, immediate operands are always preceded by the dollar sign, $. What Intel would write as PUSH DWORD 32, AT&T would write as pushl $32. This helps the assembler recognize immediate operands.
*
AT&T documentation refers to "sections" where we would say "segments." A segment override is thus a section override in AT&T parlance. This doesn't come into play much because segments are not a big issue in 32-bit flat model programming. Still, be aware of it.
*
Not all Intel instruction mnemonics have AT&T equivalents. JCXZ, JECXZ, LOOP, LOOPZ, LOOPE, LOOPNZ, and LOOPNE do not exist in the AT&T mnemonic set, and gcc never generates code that uses them. This won't be a problem for us, as we're using NASM, but you won't see these instructions in gdb displays.
*
In the AT&T syntax, displacements in memory references are signed quantities placed outside parentheses containing the base, index, and scale values. I'll treat this one separately a little later, as you'll see it a lot in .s files and you should be able to understand it.
; hello.asm a first program for nasm for Linux, Intel, gcc
;
; assemble: nasm -f elf -l hello.lst hello.asm
; link: gcc -o hello hello.o
; run: hello
; output is: Hello World
SECTION .data ; data section
msg: db "Hello World",10 ; the string to print, 10=cr
len: equ $-msg ; "$" means "here"
; len is a value, not an address
SECTION .text ; code section
global main ; make label available to linker
main: ; standard gcc entry point
mov edx,len ; arg3, length of string to print
mov ecx,msg ; arg2, pointer to string
mov ebx,1 ; arg1, where to write, screen
mov eax,4 ; write sysout command to int 80 hex
int 0x80 ; interrupt 80 hex, call kernel
mov ebx,0 ; exit code, 0=normal
mov eax,1 ; exit command to kernel
int 0x80 ; interrupt 80 hex, call kernel
یه فرق دیگه هم هست.در این مورد باید گفت که همچنین چیزی وجود نداره و برای دستورات اسمبلی پی سی هیچ تفاوتی نمی کنه که در چه سیستم عاملی نو شته بشه یعنی همه جا دستور mov des,source به همین صوذت هست اون چیزی که شما می گید در مورد دستورات اسمبلی به فرمت AT&T مربوط به زبان سی هست یعنی اینکه شما می توانید با استفاده از تگ __asm__ دستورات اسمبلی رو در سی بنویسید اینجاست که در سینتکس AT&T می گه دستور mov به این صورت باید باشه: mov %source,%des این یعنی اینکه جای مبدا و مقصد در این روش عوض شده البته لازم به ذکره که این اصلا ربطی به اسمبلی نداره باید دقت کرد که اسمبلی مجموعه ای از دستورات که برای اسمبلر قابل فهم هستش نه یک زبان برنامه سازی یعنی شما باید در اسمبلی قطعاتتون رو مشخص کنید و بعد دستورات رو در هر قطعه تنطیم کنید.
اونم اینه که جای source و dest توی window و linux فرق داره!
یونس جان اول اینکه چرا وبلاگت را پروندی؟!!!!!!!!!!!راستش بیشتر بخاطر این بود که فرصت نوشتن توی وبلاگ رو نداشتم...
از راهنمایی هات ممنون. از همون اول هم میدونستم کتاب مزیدی را باید برای چی بخونم. سعی می کنم آپ تو دیت باشم :دیهرکدوم که بکارت میاد!
حالا من دستورات AT&T را یاد بگیرم یا Intel؟ کدومشون بهترند؟