400 likes | 627 Views
. ?10? ????. 2007?11?. ????. 3. ??. ??(structure)???????????????????,???????????(field)????????????????????,???????????????????????????????????:Windows?????COORD?????????X?Y??????,?X??????????0,?Y????2?COORD STRUCTX WORD ?Y WORD ?COORD ENDS???????????????:1?????;2????????????????,??????(structure variables);3??????????????.
E N D
1. ???? ???????????????
3. 2007?11? ???? 3 ?? ??(structure)???????????????????,???????????(field)????????????????????,?????????????????????????????????
??:Windows?????COORD?????????X?Y??????,?X??????????0,?Y????2?
COORD STRUCT
X WORD ?
Y WORD ?
COORD ENDS
???????????????:
1?????;
2????????????????,??????(structure variables);
3??????????????
4. 2007?11? ???? 4 ????
????STRUCT?ENDS??????????????,???????????????????????????:
?? STRUCT
????
?? ENDS
?????????????
?????
?????????????,??????????????????????,???????????????:
???:????(?)?????????
???:???(“”,’’)?????????????
??:???????????????????
??:????????,??DUP???????????
5. 2007?11? ???? 5 ??????
?????????????,??????(structure variables),??????????,????????????<>(????{}),?????????????;??????????????????
.data
point1 COORD <5,10>
point2 COORD <>
worker Employee <>
?????????????????????????Employee???IdNum?:
person1 Employee <”55522333”>
??????????????,???????????,??????????????????????????????,?????WriteString????,??????????????
6. 2007?11? ???? 6 ?????????????????????????????,????????IdNum?????LastName?:
person3 Employee < ,”Jones”>
???????????,????DUP???????????????,?????????,????????0?????,????????SalaryHistory???????????0:
person4 Employee <,,,2 DUP(20000)>
?????????????,??AllPoints???????????<0,0>:
NumPoints=3
AllPoints COORD NumPoints DUP(<0,0>)
7. 2007?11? ???? 7 ??????
TYPE?SIZEOF???????????????????????
8. 2007?11? ???? 8 ????
??????????????????????
?????
????????????(?ESI)???????,????????????????????????????????
????????????PTR???:
mov esi,OFFSET worker
mov ax,(Employee PTR [esi]).Years
???????????,?? Years???????????????:
mov ax, [esi].Years ;invalid
9. 2007?11? ???? 9 ??????
???????????????????????????
??:AllPoints.asm?
??:??????(ShowTime.asm)?
10. 2007?11? ???? 10 ?????
???????????????,????????????(nested structure definitions)?
????Rectangle????????????????????,?????COORD??:
Rectangle STRUCT
UpperLeft COORD <>
LowerRight COOED <>
Rectangle ENDS
Rectangle???????????????,???????COORD?,??????????:
rect1 Rectangle <>
rect4 Rectangle <<10,10>,<50,20>>
11. 2007?11? ???? 11 ??????????????:
mov rect1.UpperLeft.x,10
????????????????????,??????????Y?????40,????ESI??:
mov esi,OFFSET rect1
mov (Rectangle PTR [esi]).UpperLeft.Y,10
OFFSET??????????????????,???????:
mov edi,OFFSET rect2.LowerRight
mov (COORD PTR [edi]).x,50
mov edi,OFFSET rect2.LowerRight.x
mov WORD PTR [edi],50
??:????(Drunkard’s Walk)?
12. 2007?11? ???? 12 ????????
????????????????????????,??????????,??(union)??????????????????????????????????????????????,??????????UNION?ENDS???????:
unionname UNION
union-fields
unionname ENDS
??????????,???????:
structname STRUCT
structure-fields
UNION unionname
union-fields
ENDS
structname ENDS
13. 2007?11? ???? 13 ????????????????,????????????????????????,Integer???????????????????:
Integer UNION
D DWORD 0
W WORD 0
B BYTE 0
Integer ENDS
???????????????????????,?????????????
14. 2007?11? ???? 14 ?????????
????????????????????,?????????:???????????????Integer????????:
val1 Integer <12345678h>
val2 Integer <100h>
val3 Integer <>
??????????????????????????????????????Integer????,???????????????????????:
mov val3.B,al
mov val3.W,ax
mov val3.D,eax
?????????????:INPUT_REC_STRUCT?
15. 2007?11? ???? 15 ? ???(macro procedure)???????????????????,??????????????????????????,????????????????????
?????????????(??????),??????????????,???????INCLUDE???????????????????????????????????????????,???????????????????????,?????????,???????????????
???,????????,?????????CALL?RET????????????????:?????????????,??????????????????????????
16. 2007?11? ???? 16 ???NewLine????????Crlf??????:
NemLine MACRO
call Crlf
ENDM
?????????????,?????????,??????:
.code
NewLine
?????????????NewLine????,?????????????:
call Crlf
???????????????????????????,???????TEXTEQU??????????,?????????????????,??????TEXTEQU?????????
17. 2007?11? ???? 17 ????
????MACRO?ENDM???????????????,?????:
macroname MACRO parameter1,parameter2 …
ENDM
statement-list
MACRO?ENDM???????????????????????????????????,??????????
????
????REQ???????????????,????????????????,???????????
???
????????????(;;)?????????????,??????????????
18. 2007?11? ???? 18 ??ECHO???
ECHO???????????????????????????mPutchar?,????????????“Expanding The mPutchar macro”??:
mPutchar MACRO char:REQ
ECHO Expanding the mPutchar macro
puch eax
mov al,char
call WriteChar
pop eax
ENDM
19. 2007?11? ???? 19 ????
?????????????????????,??????????????????????:
??? ??1,??2 …
???(macroname)??????????????????????,??????????????1,??2????????,?????????????????????,???????????????????????????????????????????????,??????????;??????????????????,???????????????
??mPutChar:
20. 2007?11? ???? 20 ????
mWriteStr?
mReadStr?
mGotoxy?
?????:??????????????????????????????
mDumpMem?
21. 2007?11? ???? 21 ?????????
???????????,???????????????????????????:
mWrite MACRO text
LOCAL string ;;local lable
.date
string BYTE text,0 ;;define the string
.code
push edx
mov edx,OFFSET string
call Writestring
pop edx
ENDM
22. 2007?11? ???? 22 LOCAL??????????mWrite??????????????,??????????mWrite????????????????,??????????mWrite?,??????????????:
mWrite “Please enter your first name”
mWrite “Please enter your last name”
???????????????????????????????????:
23. 2007?11? ???? 23 mWrite “Please enter your first name”
1 .date
1 ??0000 BYTE “Please enter your first name”, 0
1 .code
1 push edx
1 mov edx, OFFSET ??0000
1 Call Writestring
1 pop edx
mWrite “Please enter your last name”
1 .date
1 ??0000 BYTE “Please enter your last name”, 0
1 .code
1 push edx
1 mov edx, OFFSET ??0000
1 Call Writestring
1 pop edx
????????????“??nnn”,??nnn??????????????????????LOCAL???,????????????
24. 2007?11? ???? 24 ????
??????????????????,??????????,??????????????????,????(???)????????????????????????,????????(nested macro)??????????????,???????????????,????????????????????????????????????
25. 2007?11? ???? 25 ??????? ?????????????????????????,?????????????:
IF condition
statement
[ELSE
statements]
ENDIF
?????????????????,???????????“????”???,??????????????ENDIF????????????,????????????????????????????????
26. 2007?11? ???? 26 ???????
27. 2007?11? ???? 27 ???????
???????????????????,???????????,???????????????????????????????,???IFB(if blank)???,??????????????;?????IFNB(if not blank)???,????????????
EXITM????????????,?????????????
28. 2007?11? ???? 28 ?????????
????????????????????????,??????????????:
paramname := <argument>
???mWriteLn??????????????,?????????,??????????????????????
mWriteLn MACRO text :=<“ ”>
mWrite text
call Crlf
ENDM
????????(“”)????,??????????????,???????????????????
29. 2007?11? ???? 29 ?????
????????????????????????:
LT ??
GT ??
EQ ??
NE ???
LE ????
GB ????
30. 2007?11? ???? 30 IF,ELSE?ENDIF???
IF???????????????????????????????????????,?????????????????????????IF?ENDM:
IF expression
statement-list
ENDIF
????????IF,ELSE?ENDIF:
IF expression
statement-list
ELSE
statement-list
ENDIF
??:mGotoxyConst??
31. 2007?11? ???? 31 IFIDN?IFIDNI???
IFIDN??????????????,?????????IFIDNI???????????????????(?????)????,?????????TRUE????????????????????????????,IFIDNI?????,???????:
IFIDNI <symbol>,<symbol>
statements
ENDIF
IFIDN????IFIDNI??????
??:mReadBuf??
32. 2007?11? ???? 32 ?????
?4???????????????????:
33. 2007?11? ???? 33 ?????(&)
?????(&)???????????????????????
?????(%)
?????(%)?????????????????????????TEXTEQU?????,%?????????????????????
??????(%)???????????????,?????????????????????????
34. 2007?11? ???? 34 ?????(<>)
?????(<>)?????????????????????,????????<>?????????????????????????(,)????(%)????(\)???(;)???????,?????????,????????????????????
???????(!)
???????(!)??????????????????:???????????????????????
35. 2007?11? ???? 35 ???
?????????,????????????????,?????,??????EXITM?????????(??????)?
??????,????symbol????IsDefined????(-1),?????(0):
IsDefined MACRO symbol
IFDEF symbol
EXITM <-1> ;;True
ELSE
EXITM <0> ;;False
ENDIF
ENDM
????????????????(())???
??:HelloNew???
36. 2007?11? ???? 36 ????? MASM???????????????????:WHILE,REPEAT,FOR?FORC??LOOP????,?????????????,???????????????????:
WHILE???????????????????
REPEAT?????????????????
FOR??????????????????????????
FORC?????????????????????????
37. 2007?11? ???? 37 WHILE???
????????????, WHILE??????????????:
WHILE constExpression
statements
ENDM
REPEAT???
REPEAT??????????????????:
REPEAT constExpression
statements
ENDM
constExpression?????????????,??????????
38. 2007?11? ???? 38 FOR???
FOR???????????????????????,????????????????????????:
FOR parameter,<arg1,arg2,…>
statements
ENDM
???????,??(parameter)????arg1;??????,??????arg2;??????????????????????
39. 2007?11? ???? 39 FORC???
FORC????????????????????????,????????????????,????:
FORC parameter,<string>
statements
ENDM
????????,??(parameter)????????????;??????,??????????????;????,????????
40. 2007?11? ???? 40 ??:??List.asm
??????REPEAT?????????????????????,??????????????????????????????????????????????????;?????,???????????????????????,????????????????????