assembly language Basic data types

Source: Internet
Author: User

This article provides an overview of the basic data types in the 8086 assembly, such as Integer, character, string, array, struct definition and reference methods.

One, Integer

In the assembly, integers can be divided into bytes (db), Word (DW), Gemini (DD) and other types

<1> definition of integer variables

Integer definition Format: (variable name) (data type) (data)

Data segmentyear    -  5 day8data ends    

<2> references to integer variables

After defining the integer variable and pointing the DS to the address of the data segment, the variable name can be used directly in the assembly language code, and the variable name is used almost the same way as the high-level language (such as C language);

Such as:

Data Segmenta DW1,2B DW2Data Endscode segment assumeCS:Codeds:DataStart:       movAx, Datamovds, AxmovAx, aAddAx, bmovAX, A +2       AddAx, bmovAh, 4chint21hcode ends End start

In this code, the DW type array variable A and the DW type variable b are defined, and the function of a[0] + B and a[1] + B is implemented;

In assembly language, the variable name = [variable offset address], the assembler compiles the source code, and converts the variable name to the direct addressing of the corresponding variable offset address;

Variable name + idata = [variable offset address + idata];

Variable name [reg] = [variable offset address + (REG)], similar to register relative addressing;

The representation and processing of characters and strings in memory

<1> Definition of characters

define the format: (character variable name) (data type) (data)

1) for visible characters , the ASCII value can be represented by the visible character plus single quotation marks;

2) for invisible characters , it can only be represented by its ASCII value, such as carriage return line break: 0AH, 0DH

<2> Definition of strings

String definitions use single or double quotation marks to cause multiple characters, such as "Hello world! ”

Data SegmentStrDb'Hello, world!.','$'enmsg db 0ah, 0DH,'$'Data Endscode segment assumeCS:Codeds:DataStart:       movAx, Datamovds, AxmovDX, offsetStr       movAh, 09hint21hmovDX, offset enmsgint21hmovAh, 4chint21h code ends end start

In the source file, define the STR string data structure and enmsg character data structure, and call 09h system function, output two strings;

When invoking the 09H system function call, the system outputs a string of memory units that begin with the address stored in the Register DX until a character is ' $ ';

the method and use of array definition

As in C, arrays are composed of multiple numbers of the same data type, and in assembly language, pseudo-instruction DUP is provided to define arrays;

1) One-dimensional array definition format:

(array name) (array element data type) (number of arrays) DUP (array element initial value)

(array name) (array element data type) (the initial value of an n number of elements)

2) Two-dimensional array definition format:

(array name) (array element data type) (second-dimensional array number of rows) DUP (first-dimensional array element)

Code: Defines a 20 * 16 db type array A, assigns a value of 8 to a[2][8];

Data Segmenta db -Dup -Dup0) ) Data Endscode segment assumeCS:Codeds:DataStart: movAx, Datamovds, AxmovAl2       movCl -       MulCLAddAx8       movBX, AxmovA[BX],8              movAh, 09hint21hcode ends End start

In this code, note a[bx] = (offset address of variable a) + (BX), equivalent to register relative addressing, for registers can only be index register and base register, namely Si, DI,BP, bx register.

Iv. definition method and use of structural body

<1> structure Definition

The struct definition is basically the same as the C language, in the following format:

Struct_name struct

Data_items

Struct_name ends

<2> structure Variable definition

A struct variable definition is basically the same as other data type definitions, except that the base data type is changed to Struct_name, such as

Variable_name struct_name Data

<3> Structure Assignment

The structure assignment can be partially assigned value;

data segmentcircle structx dd   y dd   radius? Circle Endsfirstcircle  Circle {}secondcircle Circle{Ten,,,}thirdcircle  Circle {  Ten,}fourthcircle Circle {ten}data ends

<4> struct Reference

struct refers to C language reference is basically the same;

data segmentcircle structx dd y dd radius? Circle Endsonecircle Circle {Ten,Ten, -}tencircle CircleTenDUP ({Ten,Ten, -}) Data Endscode segment assumeCS:Codeds:DataStart:      movAx, Datamovds, AxmovOnecircle.x, -      movOnecircle.y, -      movOnecircle.radius, -      movtencircle[0].x, -      movtencircle[1].Y, -            movAh, 4chint21hcode ends End start

PS: assembly language Compiler version MASM611, may compile errors in other compilers

five, structural body nesting

struct nesting is similar to the C language, where struct_name is considered a generic basic data type name in a nested set.

Data segmentpoint structx dd  y dd?  z DD?  Point Endspixel struct Pt point {} Color DW? Pixel Endsdata Ends

Six, the pointer

The pointer is the address in the code and does not need to be defined;

In data, the method of defining pointers is simple; in data, the use of variable names is pointer values, but the meaning of using variable names in code is not an address, such as:

Data Segmenta db0B db A;address of variable aData Endscode segment assumeCS:Codeds:DataStart:      movAx, Datamovds, AxmovBX, B;The address of variable a MOV into BX      movAL, [BX];put variable a mov into Al      movAh, 4chint21hcode ends

Note in the code MOV bx, b, B = (the offset address of variable B), instead of the same as in the data definition, a represents the offset address of variable a.

The code is compiled under MASM611 and cannot be guaranteed by other compilers.

assembly language Basic data types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.