第八章汇编语言

meyer.luisa39
  • No tags were found...

第八章汇编语言

int y,a=25,b=43,c=76;y=2(a+b)-c


y=2(a+b)-c;DATA SEGMENTA DB 25 ;AB DB 43 ;BC DB 76 ;CY DB ? ;DATA ENDS;STACK1 SEGMENT PARA STACKDW 20H DUP(0)STACK1 ENDS


y=2(a+b)-c;COSEG SEGMENTASSUME CS:COSEG,DS:DATA,SS:STACK1START: MOV AX , DATA ;DSMOV DS , AXMOV AL , A ;AADD AL , B ;(A+B)SAL AL , 1 ; 2(A+B)SUB AL , C ; 2(A+B)-CMOV Y , AL ;MOV AH,4CH ;INT 21HCOSEG ENDSEND START


MOV DSAX8E D8—— ——


ABCY192B4C00D0E0240602SALAL , 1SUB AL , CMOV AX, DATAMOV DS, DXMOV AL, AB8XXXX8ED8A0000000A20300B44CCD21MOV Y , ALMOVAH,4CHINT 21H02ADD AL, B060100


; [:] [[]][]:[] [...] [] ?,@,_$,31


MASMAAA AAD AAM AAS ADC ADD AND CALL CBW CLC CLDCLI CMC CMP CMPS CWD DAA DAS DEC DIV ESC HLTIDIV IMUL IN INC INT INTO IRET JA JAE JB JBEJCXZ JE JG JGE JL JLE JMP JNA JNAE JNB JNBEJNE JNG JNGEJNL JNLE JNO JNP JNS JNE JO JPJPE JPO JS JZ LAHF LDS LEA LES LOCK LODS LOOPLOOPE LOOPNE LOOPNZ LOOPZ MOV MOVS MUL NEG NOPNOT OR OUT POP POPF PUSH PUSHF RCL RCR REP REPEREPNE REPNZ REPZ RET ROL ROR SAHF SAL SAR SBB SCASSHL SHR STC STD STI STOS SUB TEST WAIT XCHG XLAT XOR


MASMAH AL AX BH BL BXCH CL CX DH DL DXCS DS ES SSBP DI SI SPASSUME CODE MACRO DB DD DW END ENDM ENDP ENDSEQU EXTRN GROUP LABEL MODROM NAME NOSEGFIX ORGPROC INCLUDE PUBLIC PURGE RECORD SEGFIX SEGMENTABS AT BYTE COMMON DUP EQ FAR GE GT HIGH LEN LELENGTH LOW LT MASK MEMORY MOD NE NEAR NOTHINGOFFSET PAGE PARA PREFIX PTR SEG SHORT SIZESTACK THIS TYPE WIDTH


1. EQU CONST EQU 10ADR1 EQU DS:[BP+14H]ADR2 EQU CONST +10COUN EQU VAR EQU


DB/DW/DD 1,2,...DATASEGMENTDA1 DB 9AHDA2 DW 5678HDA3 DD 12345678HDATAENDS


DB/DW/DD DA_BYTE1 DB 50HDA_BYTE2 DB 10H,20H,30H,40HDA_WORD1 DW 0A34HDA_WORD2 DW 1234H,5678H,9ABCHDA_DWORD DD 12345678H,9ABCDEFH


DB/DW/DD DB255DWDD1~2STRING1 DB STRINGSTRING2 DW STRINGSTRING3 DD STRING


STRING1 DBSTRINGSTRING2 DWSTRINGSTRING3 DD STRINGSTRING1 535452494E4754534952474ESTRING2 STRING3 5453000049520000474E0000


DB/DW/DD DA_BYTE3DA_WORD3DB ?,?DW ?,?


DB/DW/DD DUPDA_B1 DB 10H DUP(?)DA_B2 DB 20H DUP(‘ABCD’)DA_W1 DW 10 DUP(4)DA_W2 DW 10 DUP(-1,1)DA_B3 DB 10H DUP(4 DUP(3),8)


1. B,O,D,H(1).MOV AL, 0A9H MOV BX, ‘AB’(2) MOV AL, DS: [340H](3)DB 12H, 34H


2. (1) ,,DATA_VAR DB 40H DUP (?)DATA_VAR+08HDATA_VAR [BX] [DI]


2. (2)DWDDNUM1 DB 10H DUP (?)NUM2 DW 10H DUP (?)ARRAY DB 10H DUP (‘ABCD’)ADR1 DW ARRAYADR2 DD ARRAY


3. • • • NEAR: FAR1NEXTMOV AX 3000


2LABELLABEL LABEL LABEL NEAR/FARSUB1_FAR LABEL FARSUB1 MOV AX1234H LABEL DB/DW/DDDATA _BYTE LABEL BYTEDATA _WORD DW 20H DUP563H


+–+–*/MODSHRSHL+–1 + 21 – 21 * 21 / 21 MOD 21 SHR 1 SHL


NUM = 15*5;NUM=75NUM = NUM/8;NUM=9NUM = NUM MOD 5 ;NUM=4NUM = -NUM-6 ;NUM= -10NUM = -NUM ;NUM= 10ORG 30H ;30HDA1 DB ‘ABCDEFGH’DA2 DB ‘IBM PC COMPUTER’COUNT EQU DA2 - DA1 ;38H-30H=8DA3 EQU DA2+4


NUM=11011011BDATA1 DW NUM SHL 3 , NUM SHR 2...MOV AX , NUM SHL 3MOV BX , NUM SHR 2MOV CX , NUM SHL 8MOV CX , NUM SHL 16MOV DX , NUM SHR 8MOV DX , NUM SHR 16 DATA1 DW 6D8H , 36H...MOV AX , 011011011000BMOV BX , 00110110BMOV CX , 1101101100000000BMOV CX , 0MOV DX , 0MOV DX , 0


MOV AX,CX SHL 5MOV DX,DATA1 SHR 3


2NOTANDORXORNOT1 AND 21 OR 21 XOR 2


MOV AL , NOT 0F0HMOV DX , NOT 0F0HMOV BL , 55H OR 0F0HAND BH , 55H AND 0F0HXOR CX , 55H XOR 50HMOV AL , 0FHMOV DX , 0FF0FHMOV BL , 0F5HAND BH , 50HXOR CX , 5


3EQNELTLEGTGE1 EQ 21 NE 21 LT 21 LE 21 GT 21 GE 21 < 21 21 >= 2


DATA SEGMENTORG 10HNUM1=1234NUM2=1234HDA_BYTE DB 10H DUP(0)DA_WORD DW 10H DUP(0)DA_VAR1 DWNUM2+DA_BYTE GT NUM1+DA_WORDDA_VAR2 DB NUM1 LE NUM2DATA ENDS...MOV AX , NUM1 LT NUM2MOV BL , NUM1 GE NUM2MOV CX , DA_WORD GT DA_BYTE


...DA_VAR1 DW 0FFFFHDA_VAR2 DB 0FFH...MOV AX , 0FFFFHMOV BL , 0MOV CX , 0FFFFH...


•SEG : •OFFSET:•TYPE:•LENGTH:•SIZE:SIZE= TYPE* LENGTH


DATA7A4EHDATA SEGMENTORG 30HDA1 DB 20H DUP(12H)DA2 DW DA1...DATA ENDS...MOV AX , SEG DA1MOV BX , SEG DA2MOV SI , OFFSET DA1MOV CX , DA2MOV DI , OFFSET DA2MOV DX , OFFSET DA1+4 MOV AX , 7A4EHMOV BX , 7A4EHMOV SI , 30HMOV CX , DA2MOV DI , 50HMOV DX , 34H


TYPE BYTEWORDDWORD124NEARFAR-1-2


DA_BYTE DB 12HDA_WORD DW 3456HDA_DWORD DD 789AH...MOV AL , TYPE DA_BYTEMOV BL , TYPE DA_WORDMOV CL , TYPE DA_DWORD...MOV AL , 1MOV BL , 2MOV CL , 4


LENGTHSIZE LENGTHDUPLengthDUPDUP1 SIZESIZELENGTHTYPE


DATA SEGMENTVAR1 DB 10H DUP(0)VAR2 DB 10H, 20H, 30H, 40HVAR3 DW 10H DUP(‘A’, 4 DUP(3))VAR4 DB ‘COMPUTER’DATA ENDS...MOV AL , LENGTH VAR1 ;MOV AH , SIZE VAR1 ;MOV BL , LENGTH VAR2 ;MOV BH , SIZE VAR2 ;MOV CL , LENGTH VAR3 ;MOV CH , SIZE VAR3 ;MOV DL , LENGTH VAR4 ;MOV DH , SIZE VAR4 ;(AL)=10H(AH)=10H(BL)=1(BH)=1(CL)=10H(CH)=20H(DL)=1(DH)=1


ARRAYARRAY DW 20H DUP(4)...XOR AX , AXMOV SI , OFFSET ARRAYADD SI , SIZE ARRAY-TYPE ARRAYMOV CX , LENGTH ARRAYLOP: ADD AX , [SI]SUB SI , TYPE ARRAYLOOP LOP


5PTR: PTR BYTE ,WORD,DWORD NEAR FARDA_BYTE DB 20H DUP(0)DA_WORD DW 10H DUP(0)MOV WORD PTR DA_BYTE [10], AXADD BYTE PTR DA_WORD [DI], BLINC BYTE PTR [SI]SUB WORD PTR[BX],30HJMP FAR PTR SUB1


THISTHIS THISEQUTHISDATA _BYTE EQU THIS BYTEDATA _WORD DW 20H DUP0JUMP_FAR EQU THIS FARJUMP_NEAR XOR AX AX


HIGH LOW


DATA SEGMENTORG 20HCONST EQU 0ABCDHDATA1 DB 10H DUP(?)DATA2 DW 20H DUP(?)...DATA ENDS...MOV AH , HIGH CONSTMOV AH , 0ABHMOV AL , 0CDHMOV BH , 0MOV BL , 30HMOV CL , 68HMOV AL , LOW CONSTMOV BH , HIGH (OFFSET DATA1)MOV BL , LOW (OFFSET DATA2)MOV CL , LOW (CONST SHL 3)


() 123456789() 10LENGTH , SIZEPTR , OFFSET, SEG , TYPE , THISHIGH , LOW+, – ()* , / , MOD , SHR , SHL+ , –EQ , NE , LT , LE , GT , GENOTANDOR , XOR


1. SEGMENT [] [] []... ENDS(Align Type)PAGE():256PARA():16WORD():BYTE():


(Combine Type)•NONE•PUBLIC•COMMON


(Combine Type)• STACKPUBLICSSSP• AT• MEMORY(Class)


2. ASSUME ...DS_DATA SEGMENTVAR1 DB 12HDS_DATA ENDSES_DATA SEGMENTVAR2 DB 34HES_DATA ENDSCODE SEGMENTVAR3 DB 56H


ASSUME CS:CODE , DS:DS_DATASTART: .........INC VAR1INC VAR2INC VAR3...CODE ENDSEND STARTNOTHING ASSUME DSNOTHINGDSASSUME NOTHING 4R


•DS,ESDATA_DS SEGMENTDB1 DB 10H DUP(?)DATA_DS ENDSDATA_ES SEGMENTDB2 DB 20H DUP(?)DATA_ES ENDSCODE SEGMENTASSUME CS:CODE , DS:DATA_DS , ES:DATA_ESSTART: MOV AX , DATA_DS ;DSMOV DS , AXMOV AX , DATA_ES ;ESMOV ES , AX...CODE ENDS


•SS(1) STACK1 SEGMENT PARA STACKDW 20H DUP(?)STACK1 ENDS(2) STACK2 SEGMENTDW 30H DUP(?)TOP LABEL WORDSTACK2 ENDS...CODE SEGMENT...MOV AX , STACK2 ;SSMOV SS , AXMOV SP , OFFSET TOP ;SP


• CS...CODESTART:...............CODESEGMENTASSUME CS:CODE , .........ENDSEND START


PROC [NEAR/FAR]...RET ENDPRETCALL


1. ORG , $ORG $ ORG , $DATASEGMENTORG 30HDB1 DB 12H , 34HORG $+20HSTRING DB ‘STRING’DATA ENDS


1. ORG , $ORG , $DATA SEGMENTDA1 DB 10H DUP(?)DA2 DB 12H , 34HDA3 DW 56H , $+10H , 78H , $+20H...DATA ENDS


1. ORG , $ORG , $CODECODEMOV AX , 0050HMOV BX , 0053HSEGMENT...ORG 50HMOV AX , OFFSET $MOV BX , OFFSET $...ENDS


2. EVEN 3. INCLUDEINCLUDE INCLUDEINCLUDEFILE.MACB:\MASM\ABC.ASM4. PUBLICPUBLIC 12 ......5. EXTRN EXTRN 1 2 ...


PUBLIC NUM1 , STRING , SUB1 , LOOP1DATA1 SEGMENTNUM1EQU 1234H...STRING DB ‘CHARACTER STRING’...DATA1 ENDS...CODE1 SEGMENT...SUB1 PROC FARLOOP1: .........SUB1 ENDPCODE1 ENDSEND


EXTRNEXTRNCODE2CODE2NUM1:ABS , STRING:BYTESUB1:FAR , LOOP1:NEAR:SEGMENT:MOV AX , NUM1LEA BX , STRING:CALL SUB1:JMP FAR PTR LOOP1:ENDSEND


5. TITLE TITLE 80TITLE EXAMPLEPROGRAM


MULTAX10PUSH BXSAL AX,1MOV BX,AXSAL AX,1SAL AX,1ADD AX,BXPOP BXENDMMACRO


1. MACRO [12...]...ENDMEXCHANGE MACRO MEM1,MEM2,REGMOVXCHGMOVENDMREG,MEM1REG,MEM2MEM1,REG


2. [12...]EXCHANGEDA_BY1 , DA_BY2 , AL3.


;MULTAX10 MACROPUSH BXSAL AX,1MOV BX,AXSAL AX,1SAL AX,1ADD AX,BXPOP BXENDM;------------------------------------------------------------EXCHANGE MACRO MEM1,MEM2,REGMOV REG,MEM1XCHG REG,MEM2MOV MEM1,REGENDM


;DATA SEGMENTDA_W01 DW 1234HDA_W02 DW 5678HDATA ENDS;STACK1 SEGMENT PARA STACKDW 20H PUP(?)STACK1 ENDS;COSEGSEGMENTASSUME CS:COSEG,DS:DATA,SS:STACK1START: MOV AX , DATAMOV DS , AX...MULTAX10;+ PUSH BX+ SAL AX , 1


+ MOV BX , AX+ SAL AX , 1+ SAL AX , 1+ ADD AX , BX+ POP BX...EXCHANGE DA_W01 , DA_W02 , CX :+ MOV CX , DA_W01+ XCHG CX , DA_W02+ MOV DA_W01 , CX...COSEG ENDSEND START


4. • &SHIFT_VAR MACRO R_M , DIRECT, COUNTMOV CL , COUNTS&DIRECT R_M , CLENDMSHIFT_VAR AXHL2SHL AX,CLSHIFT_VAR AXHR2SHR AX,CL


%%SHIF0 MACRO CNTMOV CL , CNTENDMSHIF1 MACRO REG , DIRECT ,NUMCOUNT=NUMSHIF0 %COUNTS&DIRECT REG , CLENDM;SHIF1 AX , HL , 2SHIF1 BL , AR , 3;SHIF1 AX , HL , 2+ MOV CL , 2+ SHL AX , CLSHIF1 BL , AR , 3+ MOV CL , 3+ SAR BL , CL


• EXCHANGE ,,ALMOV AL , BYTE PTR DA_WORD1XCHG AL , BYTE PTR DA_WORD2MOV BYTE PTR WORD1 , AL• ! PROMPT MACRO NUM , TEXTPROMP&NUM DB ‘&TEXT&’ENDMPROMPT 23 255 >: PROMPT23 DB ‘Expression > 255’• ;;


LOCAL LOCALLOCALMACRO


MULTIP MACRO MULT1 , MULT2 , MULT3LOCAL LOP , EXIT0MOV DX , MULT1MOV CX , MULT2XOR BX , BXXOR AX , AXJCXZ EXIT0LOP: ADD BX , DXADC AX , 0LOOP LOPEXIT0: MOV MULT3 , BXMOV MULT3+2 , AXENDM


DA1 DW 1234H , 5678HDA2 DW 120H , 210HDA3 DW 4 DUP(?)...MULTIP DA1 , DA2 , DA3+ MOV DX , DA1+ MOV CX , DA2+ XOR BX , BX+ XOR AX , AX+ JCXZ ??0001+??0000:ADD BX , DX+ ADC AX , 0+ LOOP ??0000+??0001: MOV DA3 , BX


+ MOV DA3+2 , AX...MULTIP DA1+2 , DA2+2 , DA3+4+ MOV DX , DA1+2+ MOV CX , DA2+2+ XOR BX , BX+ XOR AX , AX+ JCXZ ??0003+??0002:ADD BX , DX+ ADC AX , 0+ LOOP ??0002+??0003: MOV DA3+4 , BX+ MOV DA3+6 , AX...


6. JUMP MACRO CONDJ&COND&S MACRO DESTLOCAL NEXT , EXITJ&COND NEXTJMP EXITNEXT: JMP DESTEXIT:ENDMENDM


JUMPJUMPJUMPJUMPENEGGE:JES SUB1 0:JGES SUB2 :


JE ?? 0000JMP ?? 0001?? 0000: JMP SUB1?? 0001::JGE ?? 0002JMP ?? 0003?? 0002: JMP SUB2?? 0003::


32SHIFT3212MULT12MACRO NUM1 , NUM2SAL NUM2 ,1RCL NUM1 ,1ENDMMACRO M_R1 , M_R2 , REG1 , REG2PUSHFPUSHREG1PUSHREG2SHIFT M_R1 , M_R2SHIFT M_R1 , M_R2MOVREG1 , M_R1MOVREG2 , M_R2


SHIFT M_R1 , M_R2ADDM_R2 , REG2ADCM_R1 , REG1POPREG2POPREG1POPFENDM:MULT12 DA_WORD+2,DA_WORD,AX,BX:MULT12 AX,BX,CX,DX:7.

More magazines by this user
Similar magazines