The third chapter assembly language foundation

3.2 integer addition and subtraction

TITLE the Add  and Substract ; TITLE line comments 
; author: Hk_Mayfly 
; DATE: 2019/09/06 

. Irvine32 the INCLUDE inc is ; calling function 

.code ; snippet 
main PROC ; start a process of identifying PROC (corresponding to a function defined flags start) 
    MOV EAX, 10000H ;
     the Add EAX, 20000H
     Sub EAX, 10000H 

    call DumpRegs ; call a display process CPU register values of 
main ENDP ; and 16-bit code ends Similarly, ENDP indicating the end of a process 
the eND main ; and the end start similar, showing assembler end, main reference numeral identifies the entry address process

 

TITLE the Add  and Substract ; TITLE line comments 
; author: Hk_Mayfly 
; DATE: 2019/09/06 

. Irvine32 the INCLUDE inc is ; the calling function 

. 386 ; procedure requires a minimum the CPU 
.model Flat, _stdcall ; .model generating code for the protected mode program 
.stack 4096 ;
 the ExitProcess PROTO, dwExitCode: DWORD 
DumpRegs PROTO ; PROTO prototype declaration process used by the program, corresponding to the function declaration 

.code ; snippet 
main PROC ; start a process of identifying PROC (corresponding to mark the start of a function definition ) 
    MOV EAX, 10000H ;
     the Add EAX, 20000H
    Sub EAX, 10000H 

    Call DumpRegs ; call a display process of the CPU registers 
    the INVOKE the ExitProcess, 0 ; return 0, the function call corresponds to the 
main ENDP ; and 16-bit code ends Similarly, ENDP indicating the end of a process 
the END main ; and similar end start, represents the end of the assembler, main reference numeral identifies the entry address process

 

3.3 Assembler link execution cycle

 

 

 

 

3.4 Defining Data

 Data definition syntax:

[name] directive initializer [,initializer]...

The following is an example of a data definition statement:

count DWORD 12345

Types of usage
BYTE 8-bit unsigned integer, B for byte
SBYTE 8-bit signed integer, S for signed
WORD 16-bit unsigned integer
SWORD 16-bit signed integer
DWORD 32-bit unsigned integer, D for double (word)
SDWORD 32-bit signed integer, represent SD signed bis (word)
FWORD 48 integers (far pointer protected mode)
QWORD 64-bit integer, Q represents tetrakis (word)
TBYTE 80 (10-byte) integer, T 10 bytes representatives
REAL4 32-bit (4-byte) the IEEE Short real
REAL8 64-bit (8-byte) length of the IEEE Real
REAL10 80 (10 bytes) extended the IEEE real

You can also use

Directive usage Directive usage
DB 8-bit integer DQ 64-bit integer or a real number
DW 16-bit integer DT Definition of 80 (10 byte) integer
DD 32-bit integer or a real number     

 

3.4.10 add a variable to AddSub

TITLE Add and Substract
;author:Hk_Mayfly
;date:2019/09/06

INCLUDE Irvine32.inc

.data
Num1 DWORD 10000H
Num2 DWORD 20000H
Num3 DWORd 30000H
Sum Dword 0

.code
main PROC
    mov eax,Num1
    add eax,Num2
    add eax,Num3
    mov Sum,eax

    call DumpRegs
    exit
main ENDP
END main

 

3.4.12 exercises in this section

1.Val SWORD ?

2.Val BYTE ?

3.Val SBYTE ?

4.Val QWORD ?

5.SDWORD

6.Val SDWORD 10000000000000000000000000000000

7.wArray WORD 1,2,3

8.Color BYTE "Blue"

9.dArray DWORD 50 dup(?)

10.Val BYTE 500 dup('TEST')

11.bArray BYTE 20 dup(0)

12.21h,43h,65h,87h

 

3.5 symbolic constants

3.5.5 This section exercises

1.VK_BS = 08h

2.SecondsInDay = 24*60*60

3.ArraySize = ($-myArray)

4.ArraySize = ($-myArray)/4

5.PROCEDURE TEXTQU <PROC>

6.sample TEXTQU <"Hello_World">

MyString BYTE sample

7.SetupESI TEXTQU <mov esi,OFFSET myArray>

 

3.8 Programming Exercises

1, three integer subtraction
AddSub program reference in Section 3.2, prepare three 16-bit integer subtraction procedures, only need to use the program to register, the insertion function call DumpRegs statement to display the value of the register.

TITLE Add and Substract
;author:Hk_Mayfly
;date:2019/09/06

INCLUDE Irvine32.inc

.data
Num1 WORD 1000H
Num2 WORD 2000H
Num3 WORD 4000H

.code
main PROC
    mov eax,0
    mov ax,Num3
    sub ax,Num2
    sub ax,Num1

    call DumpRegs
    exit
main ENDP
END main

 

2, data defining
write a program, requires that all data types listed in the definition contained in section 3.4, with the appropriate initialization value of each variable

TITLE Add and Substract
;author:Hk_Mayfly
;date:2019/09/06

INCLUDE Irvine32.inc

.data
Num1 BYTE 'abc'
Num2 SBYTE -10H
Num3 WORD 1000H
Num4 SWORD -1000H
Num5 DWORD 10000H
Num6 SDWORD -10000H
Num7 FWORD 100000H
Num8 QWORD 123456789ABCDEF0H
Num9 TBYTE 123456789123456789H
Num10 REAL4 2.56
Num11 REAL8 2.12345
Num12 REAL10 2.12345678


.code
main PROC
    mov eax,0
    mov al,[Num1+1]

    mov al,Num2

    mov eax,0
    mov ax,Num3

    mov ax,Num4

    mov eax,0
    mov eax,Num5

    mov eax,Num6

    call DumpRegs
    exit
main ENDP
END main

 

3, signed integer constants
to write a program, the definition of symbols corresponding to one week of daily constants, variables and create an array using these symbols as the initial value

TITLE Add and Substract
;author:Hk_Mayfly
;date:2019/09/06

INCLUDE Irvine32.inc

.data
WEEK BYTE 'Mon'
     BYTE 'Tue'
     BYTE 'Wed'
     BYTE 'Thu'
     BYTE 'Fri'
     BYTE 'Sat'
     BYTE 'Sun'

;STR_LEN = ($-WEEK)


.code
main PROC
    mov eax,0
    shr eax,16
    mov al,[WEEK];'W'
    shl eax,16
    mov ah,[WEEK+1];'e'
    mov al,[WEEK+2];'d'

    call DumpRegs

    exit
main ENDP
END main

 

4, the constant text symbol
to write a program to define several strings symbol names (characters enclosed in quotation marks). Each symbol used in the definitions of the variables are

TITLE Add and Substract
;author:Hk_Mayfly
;date:2019/09/06

INCLUDE Irvine32.inc

.data
Str1 TEXTEQU <"Hello_World!">
Str2 TEXTEQU <"I_Love_CTF!">
Str3 TEXTEQU <"REVE">
Str4 TEXTEQU <'Q'>


.code
main PROC
    mov eax,0
    mov al,[Str4]
    mov eax,[Str3]

    call DumpRegs

    exit
main ENDP
END main

Guess you like

Origin www.cnblogs.com/Mayfly-nymph/p/11477976.html