0% found this document useful (0 votes)
78 views

Lab Two

1. The document contains examples of assembly language code demonstrating various instructions including data transfer, arithmetic operations, pointers, array summation, and string manipulation. 2. Code samples show the use of MOV, INC, DEC, ADD, SUB, NEG, XCHG, LOOP, and other instructions to perform operations on variables, arrays, and strings. 3. Examples manipulate flags, use direct offset addressing on byte/word/doubleword arrays, demonstrate pointer usage, and copy a source string to a target string location.

Uploaded by

Yaikob Kebede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Lab Two

1. The document contains examples of assembly language code demonstrating various instructions including data transfer, arithmetic operations, pointers, array summation, and string manipulation. 2. Code samples show the use of MOV, INC, DEC, ADD, SUB, NEG, XCHG, LOOP, and other instructions to perform operations on variables, arrays, and strings. 3. Examples manipulate flags, use direct offset addressing on byte/word/doubleword arrays, demonstrate pointer usage, and copy a source string to a target string location.

Uploaded by

Yaikob Kebede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

lab Two manual movzx eax,bx ; EAX = 0000A69Bh

arithmetic and jmp and loop instruction movzx edx,bl ; EDX = 0000009Bh
1. simple add sub program movzx cx,bl ; CX = 009Bh
TITLE Add and Subtract (AddSubAlt.asm) ; Demonstrating MOVSX instruction:
; This program adds and subtracts 32-bit mov bx,0A69Bh
integers. movsx eax,bx ; EAX = FFFFA69Bh
.386 movsx edx,bl ; EDX = FFFFFF9Bh
.model flat,stdcall mov bl,7Bh
.stack 4096 movsx cx,bl ; CX = 007Bh
ExitProcess PROTO, dwExitCode:DWORD ; Memory-to-memory exchange:
DumpRegs PROTO mov ax,val1 ; AX = 1000h
.code xchg ax,val2 ; AX=2000h, val2=1000h
main PROC mov val1,ax ; val1 = 2000h
mov eax,10000h ; EAX = 10000h ; Direct-Offset Addressing (byte array):
add eax,40000h ; EAX = 50000h mov al,arrayB ; AL = 10h
sub eax,20000h ; EAX = 30000h mov al,[arrayB+1] ; AL = 20h
call DumpRegs mov al,[arrayB+2] ; AL = 30h
INVOKE ExitProcess,0 ; Direct-Offset Addressing (word array):
main ENDP mov ax,arrayW ; AX = 100h
END main mov ax,[arrayW+2] ; AX = 200h
1. data transfer instruction example ; Direct-Offset Addressing (doubleword array):
TITLE Data Transfer Examples (Moves.asm) mov eax,arrayD ; EAX = 10000h
INCLUDE Irvine32.inc mov eax,[arrayD+4] ; EAX = 20000h
.data mov eax,[arrayD+4] ; EAX = 20000h
val1 WORD 1000h exit
val2 WORD 2000h main ENDP
arrayB BYTE 10h,20h,30h,40h,50h END main
arrayW WORD 100h,200h,300h 2. arithmetic operation and flags.
arrayD DWORD 10000h,20000h TITLE Addition and Subtraction (AddSub3.asm)
.code INCLUDE Irvine32.inc
main PROC .data
; Demonstrating MOVZX instruction: Rval SDWORD ?
mov bx,0A69Bh Xval SDWORD 26
Yval SDWORD 30 exit
Zval SDWORD 40 main ENDP
.code END main
main PROC 3. pointers example
; INC and DEC TITLE Pointers (Pointers.asm)
mov ax,1000h INCLUDE Irvine32.inc
inc ax ; 1001h ; Create user-defined types.
dec ax ; 1000h PBYTE TYPEDEF PTR BYTE ; pointer to bytes
; Expression: Rval = -Xval + (Yval - Zval) PWORD TYPEDEF PTR WORD ; pointer to
mov eax,Xval words
neg eax ; -26 PDWORD TYPEDEF PTR DWORD ; pointer to
mov ebx,Yval doublewords
sub ebx,Zval ; -10 .data
add eax,ebx arrayB BYTE 10h,20h,30h
mov Rval,eax ; -36 arrayW WORD 1,2,3
; Zero flag example: arrayD DWORD 4,5,6
mov cx,1 ; Create some pointer variables.
sub cx,1 ; ZF = 1 ptr1 PBYTE arrayB
mov ax,0FFFFh ptr2 PWORD arrayW
inc ax ; ZF = 1 ptr3 PDWORD arrayD
; Sign flag example: .code
mov cx,0 main PROC
sub cx,1 ; SF = 1 ; Use the pointers to access data.
mov ax,7FFFh mov esi,ptr1
add ax,2 ; SF = 1 mov al,[esi] ; 10h
; Carry flag example: mov esi,ptr2
mov al,0FFh mov ax,[esi] ; 1
add al,1 ; CF = 1, AL = 00 mov esi,ptr3
; Overflow flag example: mov eax,[esi] ; 4
mov al,+127 exit
add al,1 ; OF = 1 main ENDP
mov al,-128 END main
sub al,1 ; OF = 1
4. array summation inc esi ; move to next character
TITLE Summing an Array (SumArray.asm) loop L1 ; repeat for entire string
INCLUDE Irvine32.inc exit
.data main ENDP
intarray DWORD END main
10000h,20000h,30000h,40000h
.code
main PROC
mov edi,OFFSET intarray ; 1: EDI = address of
intarray
mov ecx,LENGTHOF intarray ; 2: initialize loop
counter
mov eax,0 ; 3: sum = 0
L1: ; 4: mark beginning of loop
add eax,[edi] ; 5: add an integer
add edi,TYPE intarray ; 6: point to next element
loop L1 ; 7: repeat until ECX = 0
exit
main ENDP
END main
5. string manipulation
TITLE Copying a String (CopyStr.asm)
INCLUDE Irvine32.inc
.data
source BYTE "This is the source string",0
target BYTE SIZEOF source DUP(0)
.code
main PROC
mov esi,0 ; index register
mov ecx,SIZEOF source ; loop counter
L1:
mov al,source[esi] ; get a character from source
mov target[esi],al ; store it in the target

You might also like