The document provides an introduction to assembly language programming including:
- The basic elements of assembly language such as instructions, directives, constants, identifiers, and comments.
- A flat memory program template that includes TITLE, MODEL, STACK, DATA, CODE, and other directives.
- An example program that adds and subtracts integers and calls a procedure to display registers.
- An overview of the assemble-link-debug cycle used to develop assembly language programs.
An assembly (or assembler) language, often abbreviated asm, is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture's machine code instructions.
This document provides an overview of assembly language programming. It discusses what assembly language is, the advantages of using assembly language, how assemblers work to translate assembly code into machine code, the role of linkers in combining object files, and how debuggers can be used to debug assembly code. It also covers various assembly language directives like PROC, ENDP, CALL, RET, DB, DW, DD, and DS which are used to define procedures, call procedures, and reserve and initialize memory. The document concludes with a brief description of macros in assembly language.
An assembly language is a type of low-level programming language that is intended to communicate directly with a computer's hardware. Unlike machine language, which consists of binary and hexadecimal characters, assembly languages are designed to be readable by humans.
The document discusses assembly language programming and tools used in the assembly language development process. It provides information on assembly language instructions like LOOP, HLT, WAIT, ESC, and NOP. It also discusses assembler directives such as ASSUME, DB, DW, DD, DQ, DT, END, ENDP, ENDM, ENDS, EQU, EVEN, INCLUDE, MACRO and their usage. Additionally, it covers machine language, assembly language, high-level languages and advantages/disadvantages of each. Finally, it lists common assembly language development tools like editors, assemblers, linkers, locators, loaders and debuggers.
1) The document introduces 8086 assembly language programming concepts like variables, assignment, input/output, control flow, and subprograms.
2) Variables can be registers and assignment uses MOV instructions. Input/output requires calling operating system functions through software interrupts.
3) Loops can be implemented using conditional jump instructions and labels. A complete program example displays the character 'a' using MOV, INT, and return instructions.
Assembler directives and basic steps ALP of 8086Urvashi Singh
The document discusses various assembler directives used in assembly language programming. It describes directives like DB, DW, DD, DQ, DT for data declaration; ASSUME to define logical segments; END, ENDP, ENDS to mark ends; EQU to define constants; PROC and ENDP to define procedures; ORG to set the location counter; SEGMENT to define logical segments; GROUP, INCLUDE, EVEN, and ALIGN for segment organization; EXTRN and PUBLIC for external references; and TYPE and PTR for defining variable types. The directives provide necessary information to the assembler to understand assembly language programs and generate machine code.
This document describes the key elements of an assembly language program that prompts the user to enter two numbers, adds the numbers together, and displays the sum. It includes assembly language statements like instructions, directives, and macros. The program reserves memory for variables like the two numbers, uses macros to prompt for input and display output, converts numeric input from ASCII to binary, performs the addition, and converts the sum back to ASCII for display. The document provides detailed explanations of assembly language concepts like memory addressing and the purpose of directives.
This document provides information about assembly language and software interrupts in assembly language programs. It discusses general purpose registers, segment registers, directives used in assembly programs like .CODE and .DATA, and provides an example of a simple "Hello World" assembly language program. It also describes common software interrupts like INT 21h for MS-DOS services and lists some common functions accessed through INT 21h like displaying text, reading keyboard input, and getting the system time and date.
This document provides an introduction to assembly language programming fundamentals. It discusses machine languages and low-level languages. It also covers data representation and numbering systems. Key assembly language concepts like instructions format, directives, procedures, macros and input/output are described. Examples are given to illustrate variables, assignment, conditional jumps, loops and other common programming elements in assembly language.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. The document gives examples of writing simple programs that display or read characters using these instructions.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. Examples are provided to demonstrate reading and writing characters from the keyboard and display. The document concludes with an example of a complete 8086 assembly language program that displays the letter 'a' on the screen.
This document discusses procedures in assembly language. It covers defining procedures, documenting procedures, using the CALL and RET instructions to call and return from procedures, and examples of procedures including a SumOf procedure and nested procedure calls. Local variables within procedures are also mentioned.
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer KitAmit Kumer Podder
This document discusses 8086 assembly language programming and addressing modes. It contains:
- An introduction to 8086 assembly language programming and serial monitor operation on an 8086 trainer kit.
- Details on assembler directives like data declaration directives (DB, DW, DD), origin directives (ORG), end directives (END, ENDP, ENDS), and equate directives (EQU).
- An example program to multiply two 16-bit words in memory using various instructions and addressing modes.
- Recapitulations of different 8086 addressing modes like register, direct, register indirect, based indexed, and based indexed with displacement.
- A sample program to study different 8086 addressing modes on
This document provides an overview of assembly language fundamentals, including basic elements such as integer and real number constants, character and string constants, reserved words, identifiers, directives, and instructions. It describes parts of an instruction like labels, mnemonics, operands, and comments. It also explains the execution process of an instruction by the CPU, including fetching, decoding, fetching operands, executing, and storing output operands.
The document discusses stack and subroutines in assembly language programs. It explains that stack is used to store return addresses and save register contents. Subroutines allow breaking programs into modules and use CALL and RET instructions. An example program adds two numbers stored in memory locations and returns the result.
The document discusses the 8086 microprocessor and assembly language programming. It covers the 8086 block diagram and registers, memory models, instruction set, addressing modes, procedures, example programs, peripheral devices, and assembly code examples. It provides details on data types, arithmetic and logic instructions, comparisons and jumps, macros, procedures, interrupts, and interfacing assembly with high-level languages. The document is intended as reference material for learning 8086 assembly programming.
This document discusses assembly language programming concepts and provides examples of assembly language programs for the 8086 processor. It covers variables, assignment, input/output, and control flow. It also provides examples of complete assembly language programs that display characters, read keyboard input, and print strings. The document concludes with sample programming exercises involving operations like addition, subtraction, and conditional branching.
Analytical techniques in dry chemistry for heavy metal analysis and recent ad...Archana Verma
Heavy Metals is often used as a group name for metals and semimetals (metalloids) that have been associated with contamination and potential toxicity (Duffus, 2001). Heavy metals inhibit various enzymes and compete with various essential cations (Tchounwou et al., 2012). These may cause toxic effects (some of them at a very low content level) if they occur excessively, because of this the assessment to know their extent of contamination in soil becomes very important. Analytical techniques of dry chemistry are non-destructive and rapid and due to that a huge amount of soil samples can be analysed to know extent of heavy metal pollution, which conventional way of analysis not provide efficiently because of being tedious processes. Compared with conventional analytical methods, Vis-NIR techniques provide spectrally rich and spatially continuous information to obtain soil physical and chemical contamination. Among the calibration methods, a number of multivariate regression techniques for assessing heavy metal contamination have been employed by many studies effectively (Costa et al.,2020). X-ray fluorescence spectrometry has several advantages when compared to other multi-elemental techniques such as inductively coupled plasma mass spectrometry (ICP-MS). The main advantages of XRF analysis are; the limited preparation required for solid samples and the decreased production of hazardous waste. Field portable (FP)-XRF retains these advantages while additionally providing data on-site and hence reducing costs associated with sample transport and storage (Pearson et al.,2013). Laser Induced Breakdown Spectroscopy (LIBS) is a kind of atomic emission spectroscopy. In LIBS technology, a laser pulse is focused precisely onto the surface of a target sample, ablating a certain amount of sample to create plasma (Vincenzo Palleschi,2020). After obtaining the LIBS data of the tested sample, qualitative and quantitative analysis is conducted. Even after being rapid and non-destructive, several limitations are also there in these advance techniques such as more effective and accurate quantification models are needed. To overcome these problems, proper calibration models should be developed for better quantification of spectrum in near future.
The document discusses assembly language programming and tools used in the assembly language development process. It provides information on assembly language instructions like LOOP, HLT, WAIT, ESC, and NOP. It also discusses assembler directives such as ASSUME, DB, DW, DD, DQ, DT, END, ENDP, ENDM, ENDS, EQU, EVEN, INCLUDE, MACRO and their usage. Additionally, it covers machine language, assembly language, high-level languages and advantages/disadvantages of each. Finally, it lists common assembly language development tools like editors, assemblers, linkers, locators, loaders and debuggers.
1) The document introduces 8086 assembly language programming concepts like variables, assignment, input/output, control flow, and subprograms.
2) Variables can be registers and assignment uses MOV instructions. Input/output requires calling operating system functions through software interrupts.
3) Loops can be implemented using conditional jump instructions and labels. A complete program example displays the character 'a' using MOV, INT, and return instructions.
Assembler directives and basic steps ALP of 8086Urvashi Singh
The document discusses various assembler directives used in assembly language programming. It describes directives like DB, DW, DD, DQ, DT for data declaration; ASSUME to define logical segments; END, ENDP, ENDS to mark ends; EQU to define constants; PROC and ENDP to define procedures; ORG to set the location counter; SEGMENT to define logical segments; GROUP, INCLUDE, EVEN, and ALIGN for segment organization; EXTRN and PUBLIC for external references; and TYPE and PTR for defining variable types. The directives provide necessary information to the assembler to understand assembly language programs and generate machine code.
This document describes the key elements of an assembly language program that prompts the user to enter two numbers, adds the numbers together, and displays the sum. It includes assembly language statements like instructions, directives, and macros. The program reserves memory for variables like the two numbers, uses macros to prompt for input and display output, converts numeric input from ASCII to binary, performs the addition, and converts the sum back to ASCII for display. The document provides detailed explanations of assembly language concepts like memory addressing and the purpose of directives.
This document provides information about assembly language and software interrupts in assembly language programs. It discusses general purpose registers, segment registers, directives used in assembly programs like .CODE and .DATA, and provides an example of a simple "Hello World" assembly language program. It also describes common software interrupts like INT 21h for MS-DOS services and lists some common functions accessed through INT 21h like displaying text, reading keyboard input, and getting the system time and date.
This document provides an introduction to assembly language programming fundamentals. It discusses machine languages and low-level languages. It also covers data representation and numbering systems. Key assembly language concepts like instructions format, directives, procedures, macros and input/output are described. Examples are given to illustrate variables, assignment, conditional jumps, loops and other common programming elements in assembly language.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. The document gives examples of writing simple programs that display or read characters using these instructions.
This document provides an introduction to 8086 assembly language programming. It discusses key concepts like variables, assignment, input/output, control flow, and subprograms. It then describes specific 8086 instructions like MOV for assignment, ADD, INC, DEC, and SUB for arithmetic operations, and INT for input/output. Examples are provided to demonstrate reading and writing characters from the keyboard and display. The document concludes with an example of a complete 8086 assembly language program that displays the letter 'a' on the screen.
This document discusses procedures in assembly language. It covers defining procedures, documenting procedures, using the CALL and RET instructions to call and return from procedures, and examples of procedures including a SumOf procedure and nested procedure calls. Local variables within procedures are also mentioned.
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer KitAmit Kumer Podder
This document discusses 8086 assembly language programming and addressing modes. It contains:
- An introduction to 8086 assembly language programming and serial monitor operation on an 8086 trainer kit.
- Details on assembler directives like data declaration directives (DB, DW, DD), origin directives (ORG), end directives (END, ENDP, ENDS), and equate directives (EQU).
- An example program to multiply two 16-bit words in memory using various instructions and addressing modes.
- Recapitulations of different 8086 addressing modes like register, direct, register indirect, based indexed, and based indexed with displacement.
- A sample program to study different 8086 addressing modes on
This document provides an overview of assembly language fundamentals, including basic elements such as integer and real number constants, character and string constants, reserved words, identifiers, directives, and instructions. It describes parts of an instruction like labels, mnemonics, operands, and comments. It also explains the execution process of an instruction by the CPU, including fetching, decoding, fetching operands, executing, and storing output operands.
The document discusses stack and subroutines in assembly language programs. It explains that stack is used to store return addresses and save register contents. Subroutines allow breaking programs into modules and use CALL and RET instructions. An example program adds two numbers stored in memory locations and returns the result.
The document discusses the 8086 microprocessor and assembly language programming. It covers the 8086 block diagram and registers, memory models, instruction set, addressing modes, procedures, example programs, peripheral devices, and assembly code examples. It provides details on data types, arithmetic and logic instructions, comparisons and jumps, macros, procedures, interrupts, and interfacing assembly with high-level languages. The document is intended as reference material for learning 8086 assembly programming.
This document discusses assembly language programming concepts and provides examples of assembly language programs for the 8086 processor. It covers variables, assignment, input/output, and control flow. It also provides examples of complete assembly language programs that display characters, read keyboard input, and print strings. The document concludes with sample programming exercises involving operations like addition, subtraction, and conditional branching.
Analytical techniques in dry chemistry for heavy metal analysis and recent ad...Archana Verma
Heavy Metals is often used as a group name for metals and semimetals (metalloids) that have been associated with contamination and potential toxicity (Duffus, 2001). Heavy metals inhibit various enzymes and compete with various essential cations (Tchounwou et al., 2012). These may cause toxic effects (some of them at a very low content level) if they occur excessively, because of this the assessment to know their extent of contamination in soil becomes very important. Analytical techniques of dry chemistry are non-destructive and rapid and due to that a huge amount of soil samples can be analysed to know extent of heavy metal pollution, which conventional way of analysis not provide efficiently because of being tedious processes. Compared with conventional analytical methods, Vis-NIR techniques provide spectrally rich and spatially continuous information to obtain soil physical and chemical contamination. Among the calibration methods, a number of multivariate regression techniques for assessing heavy metal contamination have been employed by many studies effectively (Costa et al.,2020). X-ray fluorescence spectrometry has several advantages when compared to other multi-elemental techniques such as inductively coupled plasma mass spectrometry (ICP-MS). The main advantages of XRF analysis are; the limited preparation required for solid samples and the decreased production of hazardous waste. Field portable (FP)-XRF retains these advantages while additionally providing data on-site and hence reducing costs associated with sample transport and storage (Pearson et al.,2013). Laser Induced Breakdown Spectroscopy (LIBS) is a kind of atomic emission spectroscopy. In LIBS technology, a laser pulse is focused precisely onto the surface of a target sample, ablating a certain amount of sample to create plasma (Vincenzo Palleschi,2020). After obtaining the LIBS data of the tested sample, qualitative and quantitative analysis is conducted. Even after being rapid and non-destructive, several limitations are also there in these advance techniques such as more effective and accurate quantification models are needed. To overcome these problems, proper calibration models should be developed for better quantification of spectrum in near future.
The presentation "Hydrazine Chemistry" examines the historical evolution, industrial uses, and synthetic approaches for hydrazine and its derivatives, underscoring their critical roles in pharmaceuticals and as rocket fuel. It covers naturally occurring hydrazines like gyromitrin and advanced synthetic methods, including Myers TBS-tosylhydrazones and BTBSH for enhanced Wolff-Kishner reductions. The discussion addresses synthetic challenges, innovative strategies such as the PCUK cycle and monoalkylation with protecting groups, and their extensive applications in drug development and natural product synthesis.
Calf born With 2 head, 3 ear and 4 eye, Masha, SWE.pdfmelesemelkamu81
I am pleased to submit a case report titled" Calf born with 2 head, 3 ear and 4 eye in Masha, south west Ethiopia and this type of case report is new in the area. we confirm that the case is original.
DOSAGE FORM (Pharmaceutics) B Pharmacy sem-IUmeshMali16
This PowerPoint presentation provides a comprehensive overview of dosage forms in pharmaceutics, tailored for B. Pharmacy Semester-I students. It covers the classification, definition, and importance of different pharmaceutical dosage forms such as solid, liquid, semi-solid, gaseous, and novel drug delivery systems. The slides also highlight the advantages, limitations, and pharmaceutical considerations for formulation development. Ideal for students preparing for university exams or looking for a foundational understanding of pharmaceutics.
Towards Scientific Foundation Models (Invited Talk)Steffen Staab
Foundation models are machine-learned models that are trained on broad data at scale and are adaptable to a wide range of downstream tasks. Foundation models have been used successfully for question answering and text generation (ChatGPT), image understanding (Clip, VIT), or image generation. Recently, the basic idea underlying foundation models been considered for learning scientific foundation models that capture expectations about partial differential equations. Existing scientific foundation models have still been very much limited wrt. the type of PDEs or differential operators . In this talk, I present some of our recent work on paving the way towards scientific foundation models that aims at making them more robust and better generalisable.
Side Reactions in Peptide Synthesis: Solution and Solid phase synthesisVinayak Khairnar
The presentation on "Side Reactions in Peptide Synthesis" explores peptide synthesis through solution-phase and solid-phase methods, focusing on solid-phase peptide synthesis (SPPS) and its use of polystyrene resins. It highlights common side reactions, such as pyroglutamate formation, aspartimide formation, and racemization, and discusses control strategies like solvent selection. SPPS is presented as a robust, green chemistry technique for synthesizing peptides, DNA, and combinatorial molecules, despite challenges from side chain degradation.
Ch 1 Powerpoint - Introduction to Earth Science [Savvas].pptjoshscally027
Title: Earth’s Extremes: Glaciers and Deserts
Description:
Explore the powerful forces shaping Earth’s surface in this exciting slideshow about glaciers and deserts. Learn how icy giants slowly carve out valleys and how winds sculpt stunning desert landscapes. Through vivid images and simple explanations, discover the processes of erosion, deposition, and climate impact in two of Earth’s most extreme environments. This presentation helps students understand the surprising similarities and key differences between frozen and arid ecosystems.
This slideshow takes you on a journey through two of Earth’s most dramatic landscapes: glaciers and deserts. Discover how glaciers grind down mountains, transport massive amounts of rock, and shape U-shaped valleys, while deserts, shaped by wind and minimal rainfall, form dunes, mesas, and canyons. Learn how both environments reveal clues about Earth’s climate, water cycles, and geologic history. Perfect for classrooms or anyone curious about Earth science.
This comprehensive slideshow explores the contrasting but equally dynamic geomorphic systems of glaciers and deserts. Examine the mechanisms of glacial erosion (plucking, abrasion), the formation of features like moraines and glacial troughs, and the role of aeolian processes in desert environments. Case studies include the Sahara Desert, the Atacama, and the Antarctic ice sheet. This presentation also touches on climate influences, past glaciations, and desertification trends. Ideal for advanced Earth science courses.
Atropisomerism in Drug Discovery -Medicinal ChemistryVinayak Khairnar
The presentation focuses on atropisomerism, a type of stereoisomerism arising from restricted rotation around a bond axis due to steric hindrance or electronic factors, with applications in pharmaceutical compounds like KRAS inhibitors for lung cancer treatment. It covers the definition, energy of activation, nomenclature for assigning configurations, and catalyst-controlled stereoselective synthesis, emphasizing the time-dependent chirality and its potential impact if not properly managed. The content includes references to key studies and highlights ongoing challenges in achieving high enantiomeric excess in atropisomer-selective oxidative coupling reactions.
2. Presentation Outline
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
3. Constants
• Integer Constants
• Examples: –10, 42d, 10001101b, 0FF3Ah, 777o
• Radix: b = binary, d = decimal, h = hexadecimal, and o = octal
• If no radix is given, the integer constant is decimal
• A hexadecimal beginning with a letter must have a leading 0
• Character and String Constants
• Enclose character or string in single or double quotes
• Examples: 'A', "d", 'ABC', "ABC", '4096'
• Embedded quotes: "single quote ' inside", 'double quote " inside'
• Each ASCII character occupies a single byte
4. Assembly Language Statements
• Three types of statements in assembly language
• Typically, one statement should appear on a line
1. Executable Instructions
• Generate machine code for the processor to execute at runtime
• Instructions tell the processor what to do
2. Assembler Directives
• Provide information to the assembler while translating a program
• Used to define data, select memory model, etc.
• Non-executable: directives are not part of instruction set
3. Macros
• Shorthand notation for a group of statements
• Sequence of instructions, directives, or other macros
5. Instructions
• Assembly language instructions have the format:
[label:] mnemonic [operands] [;comment]
• Instruction Label (optional)
• Marks the address of an instruction, must have a colon :
• Used to transfer program execution to a labeled instruction
• Mnemonic
• Identifies the operation (e.g. MOV, ADD, SUB, JMP, CALL)
• Operands
• Specify the data required by the operation
• Executable instructions can have zero to three operands
• Operands can be registers, memory variables, or constants
6. • No operands
stc ; set carry flag
• One operand
inc eax ; increment register eax
call Clrscr ; call procedure Clrscr
jmp L1 ; jump to instruction with label L1
• Two operands
add ebx, ecx ; register ebx = ebx + ecx
sub var1, 25; memory variable var1 = var1 - 25
• Three operands
imul eax,ebx,5 ; register eax = ebx * 5
Instruction Examples
7. Comments
• Comments are very important!
• Explain the program's purpose
• When it was written, revised, and by whom
• Explain data used in the program
• Explain instruction sequences and algorithms used
• Application-specific explanations
• Single-line comments
• Begin with a semicolon ; and terminate at end of line
• Multi-line comments
• Begin with COMMENT directive and a chosen character
• End with the same chosen character
8. Next . . .
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
9. Flat Memory Program Template
TITLE Flat Memory Program Template (Template.asm)
; Program Description:
; Author: Creation Date:
; Modified by: Modification Date:
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.DATA
; (insert variables here)
.CODE
main PROC
; (insert executable instructions here)
exit
main ENDP
; (insert additional procedures here)
END main
10. TITLE and .MODEL Directives
• TITLE line (optional)
• Contains a brief heading of the program and the disk file name
• .MODEL directive
• Specifies the memory configuration
• For our purposes, the FLAT memory model will be used
• Linear 32-bit address space (no segmentation)
• STDCALL directive tells the assembler to use …
• Standard conventions for names and procedure calls
• .686 processor directive
• Used before the .MODEL directive
• Program can use instructions of Pentium P6 architecture
• At least the .386 directive should be used with the FLAT model
11. .STACK, .DATA, & .CODE Directives
• .STACK directive
• Tells the assembler to define a runtime stack for the program
• The size of the stack can be optionally specified by this directive
• The runtime stack is required for procedure calls
• .DATA directive
• Defines an area in memory for the program data
• The program's variables should be defined under this directive
• Assembler will allocate and initialize the storage of variables
• .CODE directive
• Defines the code section of a program containing instructions
• Assembler will place the instructions in the code area in memory
12. INCLUDE, PROC, ENDP, and END
• INCLUDE directive
• Causes the assembler to include code from another file
• We will include Irvine32.inc provided by the author Kip Irvine
• Declares procedures implemented in the Irvine32.lib library
• To use this library, you should link Irvine32.lib to your programs
• PROC and ENDP directives
• Used to define procedures
• As a convention, we will define main as the first procedure
• Additional procedures can be defined after main
• END directive
• Marks the end of a program
• Identifies the name (main) of the program’s startup procedure
13. Next . . .
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
14. TITLE Add and Subtract (AddSub.asm)
; This program adds and subtracts 32-bit integers.
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.CODE
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs ; display registers
exit
main ENDP
END main
Adding and Subtracting Integers
15. Example of Console Output
Procedure DumpRegs is defined in Irvine32.lib library
It produces the following console output,
showing registers and flags:
EAX=00030000 EBX=7FFDF000 ECX=00000101 EDX=FFFFFFFF
ESI=00000000 EDI=00000000 EBP=0012FFF0 ESP=0012FFC4
EIP=00401024 EFL=00000206 CF=0 SF=0 ZF=0 OF=0
16. Suggested Coding Standards
• Some approaches to capitalization
• Capitalize nothing
• Capitalize everything
• Capitalize all reserved words, mnemonics and register names
• Capitalize only directives and operators
• MASM is NOT case sensitive: does not matter what case is used
• Other suggestions
• Use meaningful identifier names
• Use blank lines between procedures
• Use indentation and spacing to align instructions and comments
• Use tabs to indent instructions, but do not indent labels
• Align the comments that appear after the instructions
17. Understanding Program Termination
• The exit at the end of main procedure is a macro
• Defined in Irvine32.inc
• Expanded into a call to ExitProcess that terminates the program
• ExitProcess function is defined in the kernel32 library
• We can replace exit with the following:
push 0 ; push parameter 0 on stack
call ExitProcess ; to terminate program
• You can also replace exit with: INVOKE ExitProcess, 0
• PROTO directive (Prototypes)
• Declares a procedure used by a program and defined elsewhere
ExitProcess PROTO, ExitCode:DWORD
• Specifies the parameters and types of a given procedure
18. Modified Program
TITLE Add and Subtract (AddSubAlt.asm)
; This program adds and subtracts 32-bit integers
.686
.MODEL flat,stdcall
.STACK 4096
; No need to include Irvine32.inc
ExitProcess PROTO, dwExitCode:DWORD
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
push 0
call ExitProcess ; to terminate program
main ENDP
END main
19. Next . . .
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
20. Assemble-Link-Debug Cycle
• Editor
• Write new (.asm) programs
• Make changes to existing ones
• Assembler: ML.exe program
• Translate (.asm) file into object
(.obj) file in machine language
• Can produce a listing (.lst) file
that shows the work of assembler
• Linker: LINK32.exe program
• Combine object (.obj) files with
link library (.lib) files
• Produce executable (.exe) file
• Can produce optional (.map) file
Edit
Assemble
Link
Run
prog.asm
prog.obj prog.lst
prog.exe prog.map
library.lib
Debug
21. Assemble-Link-Debug Cycle – cont'd
• MAKE32.bat
• Batch command file
• Assemble and link in one step
• Debugger: WINDBG.exe
• Trace program execution
• Either step-by-step, or
• Use breakpoints
• View
• Source (.asm) code
• Registers
• Memory by name & by address
• Modify register & memory content
• Discover errors and go back to the editor to fix the program bugs
Edit
Assemble
Link
Run
prog.asm
prog.obj prog.lst
prog.exe prog.map
library.lib
Debug
22. Listing File
• Use it to see how your program is assembled
• Contains
• Source code
• Object code
• Relative addresses
• Segment names
• Symbols
• Variables
• Procedures
• Constants
Object & source code in a listing file
00000000 .code
00000000 main PROC
00000000 B8 00060000 mov eax,
60000h
00000005 05 00080000 add eax,
80000h
0000000A 2D 00020000 sub eax,
20000h
0000000F 6A 00 push 0
00000011 E8 00000000 E call
ExitProcess
00000016 main ENDP
END main
object code
(hexadecimal)
source code
Relative
Addresses
23. Next . . .
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
25. Data Definition Statement
• Sets aside storage in memory for a variable
• May optionally assign a name (label) to the data
• Syntax:
[name] directive initializer [, initializer] . . .
val1 BYTE 10
• All initializers become binary data in memory
26. Defining BYTE and SBYTE Data
value1 BYTE 'A' ; character constant
value2 BYTE 0 ; smallest unsigned byte
value3 BYTE 255 ; largest unsigned byte
value4 SBYTE -128 ; smallest signed byte
value5 SBYTE +127 ; largest signed byte
value6 BYTE ? ; uninitialized byte
Each of the following defines a single byte of storage:
• MASM does not prevent you from initializing a BYTE with a
negative value, but it's considered poor style.
• If you declare a SBYTE variable, the Microsoft debugger will
automatically display its value in decimal with a leading sign.
28. Defining Strings
• A string is implemented as an array of characters
• For convenience, it is usually enclosed in quotation marks
• It is often terminated with a NULL char (byte value = 0)
• Examples:
str1 BYTE "Enter your name", 0
str2 BYTE 'Error: halting program', 0
str3 BYTE 'A','E','I','O','U'
greeting BYTE "Welcome to the Encryption "
BYTE "Demo Program", 0
29. Defining Strings – cont'd
• To continue a single string across multiple
lines, end each line with a comma
menu BYTE "Checking Account",0dh,0ah,0dh,0ah,
"1. Create a new account",0dh,0ah,
"2. Open an existing account",0dh,0ah,
"3. Credit the account",0dh,0ah,
"4. Debit the account",0dh,0ah,
"5. Exit",0ah,0ah,
"Choice> ",0
❖ End-of-line character
sequence:
✧ 0Dh = 13 = carriage return
✧ 0Ah = 10 = line feed
Idea: Define all strings
used by your program in
the same area of the
data segment
30. Using the DUP Operator
• Use DUP to allocate space for an array or string
• Advantage: more compact than using a list of
initializers
• Syntax
counter DUP ( argument )
Counter and argument must be constants expressions
• The DUP operator may also be nested
var1 BYTE 20 DUP(0) ; 20 bytes, all equal to zero
var2 BYTE 20 DUP(?) ; 20 bytes, all uninitialized
var3 BYTE 4 DUP("STACK") ; 20 bytes: "STACKSTACKSTACKSTACK"
var4 BYTE 10,3 DUP(0),20 ; 5 bytes: 10, 0, 0, 0, 20
var5 BYTE 2 DUP(5 DUP('*'), 5 DUP('!')) ; '*****!!!!!*****!!!!!'
31. Defining 16-bit and 32-bit Data
• Define storage for 16-bit and 32-bit integers
• Signed and Unsigned
• Single or multiple initial values
word1 WORD 65535 ; largest unsigned 16-bit
value
word2 SWORD –32768 ; smallest signed 16-bit
value
word3 WORD "AB" ; two characters fit in a WORD
array1 WORD 1,2,3,4,5 ; array of 5 unsigned words
array2 SWORD 5 DUP(?) ; array of 5 signed words
dword1 DWORD 0ffffffffh ; largest unsigned 32-bit
value
dword2 SDWORD –2147483648 ; smallest signed 32-bit value
array3 DWORD 20 DUP(?) ; 20 unsigned double words
array4 SDWORD –3,–2,–1,0,1 ; 5 signed double words
32. QWORD, TBYTE, and REAL Data
quad1 QWORD 1234567812345678h
val1 TBYTE 1000000000123456789Ah
rVal1 REAL4 -2.1
rVal2 REAL8 3.2E-260
rVal3 REAL10 4.6E+4096
array REAL4 20 DUP(0.0)
❖ QWORD and TBYTE
✧ Define storage for 64-bit and 80-bit integers
✧ Signed and Unsigned
❖ REAL4, REAL8, and REAL10
✧ Defining storage for 32-bit, 64-bit, and 80-bit floating-
point data
33. • Assembler builds a symbol table
• So we can refer to the allocated storage space by name
• Assembler keeps track of each name and its offset
• Offset of a variable is relative to the address of the
first variable
• Example Symbol Table
.DATA Name Offset
value WORD 0 value 0
sum DWORD 0 sum 2
marks WORD 10 DUP (?) marks 6
msg BYTE 'The grade is:',0msg 26
char1 BYTE ? char1 40
Symbol Table
34. • Processors can order bytes within a word in two ways
• Little Endian Byte Ordering
• Memory address = Address of least significant byte
• Examples: Intel 80x86
• Big Endian Byte Ordering
• Memory address = Address of most significant byte
• Examples: MIPS, Motorola 68k, SPARC
Byte Ordering and Endianness
Byte 0
Byte 1
Byte 2
Byte 3
32-bit Register
MSB LSB
. . . . . .
Byte 0
Byte 1
Byte 2
Byte 3
a a+3
a+2
a+1
Memory
address
Byte 3
Byte 0
Byte 1
Byte 2
Byte 3
32-bit Register
MSB LSB
. . . . . .
Byte 0 Byte 1 Byte 2
a a+3
a+2
a+1
Memory
address
35. Adding Variables to AddSub
TITLE Add and Subtract, Version 2 (AddSub2.asm)
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.DATA
val1 DWORD 10000h
val2 DWORD 40000h
val3 DWORD 20000h
result DWORD ?
.CODE
main PROC
mov eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
mov result,eax ; store the result (30000h)
call DumpRegs ; display the registers
exit
main ENDP
END main
36. Next . . .
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
37. Defining Symbolic Constants
• Symbolic Constant
• Just a name used in the assembly language program
• Processed by the assembler pure text substitution
⇒
• Assembler does NOT allocate memory for symbolic constants
• Assembler provides three directives:
• = directive
• EQU directive
• TEXTEQU directive
• Defining constants has two advantages:
• Improves program readability
• Helps in software maintenance: changes are done in one place
38. Equal-Sign Directive
• Name = Expression
• Name is called a symbolic constant
• Expression is an integer constant expression
• Good programming style to use symbols
• Name can be redefined in the program
COUNT = 500 ; NOT a variable (NO memory allocation)
. . .
mov eax, COUNT ; mov eax, 500
. . .
COUNT = 600 ; Processed by the assembler
. . .
mov ebx, COUNT ; mov ebx, 600
39. • Three Formats:
Name EQU Expression Integer constant expression
Name EQU Symbol Existing symbol name
Name EQU <text> Any text may appear within < …>
• No Redefinition: Name cannot be redefined
with EQU
EQU Directive
SIZE EQU 10*10 ; Integer constant expression
PI EQU <3.1416> ; Real symbolic constant
PressKey EQU <"Press any key to continue...",0>
.DATA
prompt BYTE PressKey
40. TEXTEQU Directive
• TEXTEQU creates a text macro. Three Formats:
Name TEXTEQU <text> assign any text to name
Name TEXTEQU textmacro assign existing text macro
Name TEXTEQU %constExpr constant integer expression
• Name can be redefined at any time (unlike EQU)
ROWSIZE = 5
COUNT TEXTEQU %(ROWSIZE * 2) ; evaluates to 10
MOVAL TEXTEQU <mov al,COUNT>
ContMsg TEXTEQU <"Do you wish to continue (Y/N)?">
.DATA
prompt BYTE ContMsg
.CODE
MOVAL ; generates: mov al,10
41. Next . . .
• Basic Elements of Assembly Language
• Flat Memory Program Template
• Example: Adding and Subtracting Integers
• Assembling, Linking, and Debugging Programs
• Defining Data
• Defining Symbolic Constants
• Data-Related Operators and Directives
42. OFFSET Operator
.DATA
bVal BYTE ? ; Assume bVal is at 00404000h
wVal WORD ?
dVal DWORD ?
dVal2 DWORD ?
.CODE
mov esi, OFFSET bVal ; ESI = 00404000h
mov esi, OFFSET wVal ; ESI = 00404001h
mov esi, OFFSET dVal ; ESI = 00404003h
mov esi, OFFSET dVal2 ; ESI = 00404007h
❖ OFFSET = address of a variable within its segment
✧ In FLAT memory, one address space is used for code and data
✧ OFFSET = linear address of a variable (32-bit number)
43. ALIGN Directive
• ALIGN directive aligns a variable in memory
• Syntax: ALIGN bound
• Where bound can be 1, 2, 4, or 16
• Address of a variable should be a multiple of bound
• Assembler inserts empty bytes to enforce alignment
.DATA ; Assume that
b1 BYTE ? ; Address of b1 =
00404000h
ALIGN 2 ; Skip one byte
w1 WORD ? ; Address of w1 =
00404002h
w2 WORD ? ; Address of w2 =
00404004h
ALIGN 4 ; Skip two bytes
d1 DWORD ? ; Address of d1 =
00404008h
d2 DWORD ? ; Address of d2 =
0040400Ch
w1
b1
404000
w2
404004
d1
404008
d2
40400C
44. TYPE Operator
• TYPE operator
• Size, in bytes, of a single element of a data
declaration
.DATA
var1 BYTE ?
var2 WORD ?
var3 DWORD ?
var4 QWORD ?
.CODE
mov eax, TYPE var1 ; eax = 1
mov eax, TYPE var2 ; eax = 2
mov eax, TYPE var3 ; eax = 4
mov eax, TYPE var4 ; eax = 8
45. ❖ LENGTHOF operator
✧ Counts the number of elements in a single data declaration
LENGTHOF Operator
.DATA
array1 WORD 30 DUP(?),0,0
array2 WORD 5 DUP(3 DUP(?))
array3 DWORD 1,2,3,4
digitStr BYTE "12345678",0
.code
mov ecx, LENGTHOF array1 ; ecx = 32
mov ecx, LENGTHOF array2 ; ecx = 15
mov ecx, LENGTHOF array3 ; ecx = 4
mov ecx, LENGTHOF digitStr ; ecx = 9
46. SIZEOF Operator
.DATA
array1 WORD 30 DUP(?),0,0
array2 WORD 5 DUP(3 DUP(?))
array3 DWORD 1,2,3,4
digitStr BYTE "12345678",0
.CODE
mov ecx, SIZEOF array1 ; ecx = 64
mov ecx, SIZEOF array2 ; ecx = 30
mov ecx, SIZEOF array3 ; ecx = 16
mov ecx, SIZEOF digitStr ; ecx = 9
❖ SIZEOF operator
✧ Counts the number of bytes in a data declaration
✧ Equivalent to multiplying LENGTHOF by TYPE
47. Multiple Line Declarations
.DATA
array WORD 10,20,
30,40,
50,60
.CODE
mov eax, LENGTHOF array ; 6
mov ebx, SIZEOF array ; 12
A data declaration spans
multiple lines if each line
(except the last) ends with a
comma
The LENGTHOF and SIZEOF
operators include all lines
belonging to the declaration
.DATA
array WORD 10,20
WORD 30,40
WORD 50,60
.CODE
mov eax, LENGTHOF array ; 2
mov ebx, SIZEOF array ; 4
In the following example, array
identifies the first line WORD
declaration only
Compare the values returned by
LENGTHOF and SIZEOF here
to those on the left
48. ❖ PTR Provides the flexibility to access part of a variable
❖ Can also be used to combine elements of a smaller type
❖ Syntax: Type PTR (Overrides default type of a variable)
PTR Operator
.DATA
dval DWORD 12345678h
array BYTE 00h,10h,20h,30h
.CODE
mov al, dval
mov al, BYTE PTR dval
mov ax, dval
mov ax, WORD PTR dval
mov eax, array
mov eax, DWORD PTR array
78 56 34 12
dval
00 10 20 30
array
; error – why?
; al = 78h
; error – why?
; ax = 5678h
; error – why?
; eax = 30201000h
49. LABEL Directive
• Assigns an alternate name and type to a memory location
• LABEL does not allocate any storage of its own
• Removes the need for the PTR operator
• Format: Name LABEL Type
.DATA
dval LABEL DWORD
wval LABEL WORD
blist BYTE 00h,10h,00h,20h
.CODE
mov eax, dval
mov cx, wval
mov dl, blist
wval
00 10 00 20
blist
dval
; eax = 20001000h
; cx = 1000h
; dl = 00h
51. Summary
• Instruction executed at runtime
⇒
• Directive interpreted by the assembler
⇒
• .STACK, .DATA, and .CODE
• Define the code, data, and stack sections of a program
• Edit-Assemble-Link-Debug Cycle
• Data Definition
• BYTE, WORD, DWORD, QWORD, etc.
• DUP operator
• Symbolic Constant
• =, EQU, and TEXTEQU directives
• Data-Related Operators
• OFFSET, ALIGN, TYPE, LENGTHOF, SIZEOF, PTR, and LABEL