Professional Documents
Culture Documents
asm)
• ; Program Description:
• ; Author:
• ; Creation Date:
• ; Revisions:
• ; Date:
• .data
• ; (insert variables here)
• .code
• main PROC
• ; (insert executable instructions here)
• exit
• main ENDP
• ; (insert additional procedures here)
• END main
• The Assemble-Link-Execute Cycle
• The process of editing, assembling, linking, and executing assembly
language programs is summarized
• Step 1:
A programmer uses a text editor to create an ASCII text file
named the source file.
• Step 2:
The assembler reads the source file and produces an object file,
a machine-language translation of the program. Optionally, it produces
a listing file.
If any errors occur, the programmer must return to Step 1 and fix the
program
• Step 3:
The linker reads the object file and checks to see if the program contains
any calls to procedures in a link library.
The linker copies any required procedures from the link library, combines
them with the object file, and produces the executable
file.
• Step 4:
The operating system loader utility reads the executable file into memory
and branches the CPU to the program’s starting address, and the program
begins to execute.
. DATA
prompt_msg1 DB 'Please input the first number: ',0
prompt_msg2 DB 'Please input the second number: ',0
sum_msg DB 'The sum is ',0
. CODE
16: main : PROC
17. STARTUP
18: PutStr prompt_msg1 ; request first number
19: GetInt CX ; CX := first number
20: nwln
21: PutStr prompt_msg2 ; request second number
21: GetInt DX ; DX := second number
22: nwln
23: call sum returns sum in AX
24: PutStr sum_msg display sum
25: PutInt AX
26: nwln
27: done:
28: . EXIT
29:main ENDP
• 1: TITLE Add individual digits of a number ADDIGITS.ASM
• 2: COMMENT I
• 3: Objective: To find the sum of individual digits of
• 4: a given number. Shows character to binary
• 5: conversion of digits.
• 6: Input: Requests a number from keyboard.
• 7: I Output: Prints the sum of the individual digits.
• 8: .MODEL SMALL
• 9: .STACK 100H
• 10: . DATA
• 11: number_prompt DB 'Please type a number <11 digits): ',0
• 12: out_msg DB 'The sum of individual digits is: ',0
• 13: number DB 11 DUP (?)
• 14:
• 15: : . CODE
• 17: main PROC
• 18: . STARTUP
• 19: PutStr number_prompt ; request an input number
• 20: GetStr number,11 ;read input number as a string
• 21: nwln
• 22: mov BX,OFFSET number ; BX := address of number
• 23: sub DX,DX ; DX:= 0 -- DL keeps the sum
• 24: repeat_add:
• 25: mov AL, [BX] ; move the digit to AL
• 26: cmp ; if it is the NULL character
• 27: js done ; sum is done
• 28: and AL,0FH ; mask off the upper 4 bits
• 29: add DL,AL ;add the digit to sum
• 30: inc BX ; increment BX to point to next digit
• 31: jmp repeat_add ; and jump back
• 32: done:
• 33: PutStr out_msg
• 34: Putlnt DX ;write sum
• 35: nwln
• 36: . EXIT
• 37: main ENDP
• 38: END main
.data
array Byte 1,2,3,4,5,6,7,8,9,10 ; test data
multiplier Byte 10 ; test data