0% found this document useful (0 votes)
75 views19 pages

5 - Data Transfer - Coding - Only

The document contains examples of assembly language code demonstrating different operations including: 1) Using MOVZX and MOVSX instructions to move data from memory to registers with zero and sign extension. 2) Using LOOP instructions to decrement a counter and repeat a block of code multiple times. 3) Setting text colors and writing strings to the screen using loops to display text in different colors. 4) Writing integers to screen in binary, decimal and hexadecimal formats using library procedures. 5) Examples of using pointers and addressing modes to access data from variables in memory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views19 pages

5 - Data Transfer - Coding - Only

The document contains examples of assembly language code demonstrating different operations including: 1) Using MOVZX and MOVSX instructions to move data from memory to registers with zero and sign extension. 2) Using LOOP instructions to decrement a counter and repeat a block of code multiple times. 3) Setting text colors and writing strings to the screen using loops to display text in different colors. 4) Writing integers to screen in binary, decimal and hexadecimal formats using library procedures. 5) Examples of using pointers and addressing modes to access data from variables in memory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

CODING

MOVZX
INCLUDE [Link]
.data
Uarray WORD 1000h,2000h,3000h,4000h
.code
main PROC
;Move with zero extension:
movzx eax,Uarray
movzx ebx,Uarray+2
movzx ecx,Uarray+4
movzx edx,Uarray+6
call DumpRegs
exit
main ENDP
END main
MOVSX
INCLUDE [Link]
.data
Sarray SWORD -1,-2,-3,-4
.code
main PROC
; Move with sign extension:
movsx eax,Sarray
movsx ebx,Sarray+2
movsx ecx,Sarray+4
movsx edx,Sarray+6
call DumpRegs
exit
main ENDP
END main
LOOP
INCLUDE [Link]
.code
main PROC
mov ax,15 ; start ax=15
;call DumpRegs
mov ecx,6 ; set start ecx = 6
L1: ; L1 = destination
dec ax
call DumpRegs
loop L1
exit
main ENDP
END main
LOOP
INCLUDE [Link]
.code
main PROC
mov eax, 1 ;start eax=1
mov ebx, 1 ;ebx = 1
mov edx, 10 ;edx = 10
mov ecx, 6 ;loop ecx = 7 times ..6 5 4 3 2 1 0
call DumpRegs
L2:
inc ebx
dec edx
add eax, 1 ; add value in eax + 1
call DumpRegs
loop L2
exit
main ENDP
END main
COLOR

Description: Write a program that displays the


same string in four different colors, using a loop.
Call the SetTextColor procedure from the book's
link library.
Any colors may be chosen, but you may find it
easiest to change the foreground color.
INCLUDE [Link]
.data
str1 BYTE "This line is displayed in color",0
.code
main PROC
mov eax, white + (green * 16) ; white on green
background
mov ecx,4 ; loop counter
L1: call SetTextColor
mov edx,OFFSET str1
call WriteString
call Crlf
add eax,2 ; add 2 to foreground color
loop L1
exit
main ENDP
END main
PRINT OUTPUT TO SCREEN

INCLUDE [Link]
.code
main PROC
mov eax,1234h ; input argument
call WriteHex ; show hex number
call Crlf ; end of line
; no call DumpRegs bcoz no register to be display

exit
main ENDP
END main
CLEAR SCREEN BEFORE PRINT
OUTPUT

; print output
INCLUDE [Link]
.code
main PROC
call Clrscr ; clear screen first
mov eax,15 ; eax = 0000000F
call Delay
call DumpRegs
exit
main ENDP
END main
; DISPLAY A NULL-TERMINATED STRING AND
; MOVE THE CURSOR TO THE BEGINNING OF THE NEXT
SCREEN LINE.

INCLUDE [Link]
.data
str1 BYTE "Assembly language is easy!",0
.code
main PROC
mov edx,OFFSET str1
call WriteString
call Crlf
exit
main ENDP
END main
;DISPLAY A NULL-TERMINATED STRING AND
;MOVE THE CURSOR TO THE BEGINNING OF THE
NEXT SCREEN LINE (USE EMBEDDED CR/LF)
INCLUDE [Link]
.data
str1 BYTE "Assembly language is easy!",0Dh,0Ah,0
str2 BYTE "I like Assembly language!",0Dh,0Ah,0
.code
main PROC
mov edx,OFFSET str1
call WriteString
call Crlf
call Crlf
mov edx,OFFSET str2
call WriteString
exit
main ENDP
END main
DISPLAY AN UNSIGNED INTEGER IN BINARY,
DECIMAL, AND HEXADECIMAL, EACH ON A SEPARATE
LINE.
INCLUDE [Link]
.data
IntVal = 35
.code
main PROC
mov eax,IntVal
call WriteBin ; display binary
call Crlf
call WriteDec ; display decimal
call Crlf
call WriteHex ; display hexadecimal
call Crlf
exit
main ENDP
END main
ASSIGNMENT

Display a null-terminated string and move the cursor to the beginning of the
next screen line (use embedded CR/LF) for the following strings

USAGE of LIBRARY PROCEDURE


Clrscr - Clears console, locates cursor at upper left corner
DumpRegs – Displays general-purpose registers and flags
(hex)
WriteChar - Writes a single character to standard output
WriteHex - Writes an unsigned 32-bit integer in
hexadecimal format
SetTextColor - Sets foreground and background colors of all
subsequent console text output
ASSIGNMENT *SUBMIT

Write a program to display a null-terminated string and move the


cursor to the beginning of the next screen line (use embedded
CR/LF) as the following output.
Before proceed to next string, display an unsigned integer 85 in
binary, decimal, and hexadecimal, each on a separate line. Please
refer the following output.
Use the following variable definition for the remaining questions in this section:
*Submit
.data
MyByte SBYTE -4,-2,3,1
MyWord WORD 1000h,2000h,3000h,4000h

For the following statements, state whether or not the instruction is valid. Give comment
to describe the reason why the instruction become valid or invalid.

mov ax, MyByte


mov ax,MyWord

What will be the value of the destination operand after each of the following
instructions executes in sequence?
mov ax, MyWord ; c) ax:______________________________

mov ax,[MyWord + 2] ; d) ax:_____________________________

add ax, [MyWord + 2] ; e) ax:_____________________________


By Using PTR keywords, create and complete the following program
that can produce the following output based on given variables.
*submit
.data
varB BYTE 65h,31h,56h,65h
varW WORD 6543h,1202h
varD DWORD 87654321h

.code
mov _____________________ ; answer : 6556h
mov _____________________ ; answer : 21h
mov _____________________ ; answer : 02h
mov _____________________ ; answer: 8765
mov _____________________ ; answer : 12026543h
mov ax,WORD PTR [varB+2]
mov bl,BYTE PTR varD
mov bl,BYTE PTR [varW+2]
mov ax,WORD PTR [varD+2]
mov eax,DWORD PTR varW
TITLE Add and Subtract, Version 2 ([Link])
INCLUDE [Link]
.data
val1 dword 10000h
val2 dword 40000h
val3 dword 0DDh
val4 dword 200h
finalVal dword ?

.code
main PROC
add eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
add eax,val4
mov finalVal,eax ; store the result (30000h)
Call DumpRegs ; display the registers
Exit
main ENDP
END main
TITLE mul binary and hexa, Version 2 ([Link]) *TAKPAYAH
INCLUDE [Link]

.data
num1 dword 1111b
num2 dword 0Ah
finalnum dword ?

.code
main PROC

mov eax,num1 ; start 100b


mov eax,num2 ; mul 11b
mul eax
mov finalnum,eax ; store the result (12=C
call DumpRegs ; display the registers

exit
main ENDP
END main

You might also like