Understanding Segments in Assembly: Physical & Logical Segments in 80x86, Exercises of Computer Architecture and Organization

An overview of segments in assembly language programming, focusing on physical and logical segments in the context of 80x86 architecture. It covers the meaning and importance of segments, physical memory segments, and logical segments, as well as simplified segment directives and a program template for masm. It also includes instructions for generating listing and map files.

Typology: Exercises

2011/2012

Uploaded on 08/03/2012

amritkala
amritkala 🇮🇳

4.4

(17)

91 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
2
EXPERIMENT NO 03
Assembly Language Fundamentals
1. Objectives
To understand physical and logical memory segments used in 80x86 architecture
To study the basic elements of assembly language
2. Basic Information
Understanding segments is an essential part of programming in assembly language. In the
family of 8086-based processors, the term segment has two meanings:
A block of memory of discrete size, called a “physical segment.” The number of
bytes in a physical memory segment is 64K for 16-bit processors or 4 gigabytes
for 32-bit processors.
A variable-sized block of memory, called a “logical segment,” occupied by a
program’s code or data.
2.1 Physical Memory Segments
A physical segment can begin only at memory locations evenly divisible by 16, including
address 0. Intel calls such locations “paragraphs.” You can easily recognize a paragraph location
because its hexadecimal address always ends with 0, as in 10000h or 2EA70h. The 8086/286
processors allow segments 64K in size, the largest number 16 bits can represent. The 80386/486
processors still adhere to the 64K limit when running in real mode. In protected mode, however,
they use 32-bit registers that can hold addresses up to 4 gigabytes.
Segmented architecture presents certain hurdles for the assembly-language programmer. For
small programs, the limitations lose importance. Code and data each occupy less than 64K and
reside in individual segments. A simple offset locates each variable or instruction within a
segment.
Larger programs, however, must contend with problems of segmented memory areas. If data
occupies two or more segments, the program must specify both segment and offset to access a
variable. When the data forms a continuous stream across segments — such as the text in a word
processor’s workspace the problems become more acute. Whenever it adds or deletes text in
the first segment, the word processor must seamlessly move data back and forth over the
boundaries of each following segment.
docsity.com
pf3
pf4

Partial preview of the text

Download Understanding Segments in Assembly: Physical & Logical Segments in 80x86 and more Exercises Computer Architecture and Organization in PDF only on Docsity!

EXPERIMENT NO 03

Assembly Language Fundamentals

1. Objectives

 To understand physical and logical memory segments used in 80x86 architecture

 To study the basic elements of assembly language

2. Basic Information

Understanding segments is an essential part of programming in assembly language. In the family of 8086-based processors, the term segment has two meanings:

 A block of memory of discrete size, called a “physical segment.” The number of bytes in a physical memory segment is 64K for 16-bit processors or 4 gigabytes for 32-bit processors.  A variable-sized block of memory, called a “logical segment,” occupied by a program’s code or data.

2.1 Physical Memory Segments

A physical segment can begin only at memory locations evenly divisible by 16, including address 0. Intel calls such locations “paragraphs.” You can easily recognize a paragraph location because its hexadecimal address always ends with 0, as in 10000h or 2EA70h. The 8086/ processors allow segments 64K in size, the largest number 16 bits can represent. The 80386/ processors still adhere to the 64K limit when running in real mode. In protected mode, however, they use 32-bit registers that can hold addresses up to 4 gigabytes.

Segmented architecture presents certain hurdles for the assembly-language programmer. For small programs, the limitations lose importance. Code and data each occupy less than 64K and reside in individual segments. A simple offset locates each variable or instruction within a segment.

Larger programs, however, must contend with problems of segmented memory areas. If data occupies two or more segments, the program must specify both segment and offset to access a variable. When the data forms a continuous stream across segments — such as the text in a word processor’s workspace — the problems become more acute. Whenever it adds or deletes text in the first segment, the word processor must seamlessly move data back and forth over the boundaries of each following segment.

The problem of segment boundaries disappears in the so-called flat address space of 32-bit protected mode. Although segments still exist, they easily hold all the code and data of the largest programs. Even a very large program becomes in effect a small application, able to reach all code and data with a single offset address.

2.2 Logical Segments

Logical segm ents contain the three com ponents of a program : code, data, and stack. MASM organizes the three parts for you so they occupy physical segm ents of m emory. The segm ent registers CS, DS, and SS contain the addresses of the physical m emory segm ents where the logical segments reside. You can define segm ents in two ways: with sim plified segment directives and with f ull segment definitions. You can also use both kinds of segment definitions in the same program. Simplified segm ent directives hide m any of thedetails of segm ent definition and assum e the same conventions used by Microsoft high-level languages. (See the following section, “Using Simplified Segm ent Directives.”) The sim plified segm ent directives generate necessary code, specify segment attributes, and arrange segment order. Full segment definitions require m ore complex syntax but provide m ore complete control over how the assem bler generates segm ents. (See “Using Full Segm ent Def initions” later in this chapter.) If you use full segm ent definitions,you m ust write code to handle all the tasks performed automatically by the simplified segment directives.

2.3 Using Simplified Segment Directives

MASM programs consist of m odules made upof segments. Every program written only in MASM has one m ain module, where program execution begins. This m ain module can contain code, data, or stack segm ents defined withall of the sim plified segm ent directives. Any additional m odules should contain only code and data segm ents.. Every m odule that uses simplified segments must, however, begin with the .MODEL directive.

The .DATA and .CODE statements do not require any separate statements to define the end of a segm ent. They close the preceding segm ent and then open a new segm ent. The .STACK directive opens and closes the stack segm entbut does not close the current segm ent. The END statement closes the last segm ent and marks the end of the source code. It must be at the end of every module Directives are part of the assem bler syntax, butare not related to the Intel instruction set architecture. Various assemblers may generate identical machine code for the Intel processor, but their sets of directives need not to be the same. Examples: The .DATA directive identifies the area of a program that contains variables: .data variable_name type initialized_value e.g., var1 DWORD 1000h

The .CODE directive identifies the area of a program that contains instructions: .code

2.6 Map File A map file is a text file (extension MAP) that contains the information about the segments contained in a program being linked.

To generate amp file using MASM type the following command at DOSS SHELL

link/m filename

3. Experimental Work

Part 1: Write a program in assembly that adds four 16-bit numbers in and store the result.

Final_Val = val1+val2+val3+val

Use Codeview to debug the program

Part 2: Generate listing file and map file and view the results.