6_Chapter4_Data transfer_All_Coding

advertisement
Coding
MOVZX
INCLUDE Irvine32.inc
.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 Irvine32.inc
.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 irvine32.inc
.code
main PROC
mov ax,15
call DumpRegs
mov ecx,6
L1:
dec ax
call DumpRegs
loop L1
exit
main ENDP
END main
; start ax=15
; set start ecx = 6
; L1 = destination
INCLUDE Irvine32.inc
LOOP
.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
TITLE Chapter 5 Exercise 1
(ch05_01.asm)
Comment @
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 Irvine32.inc
.data
str1 BYTE "This line is displayed in color",0
.code
main PROC
mov eax, white + (green * 16) ; white on green
backgrouund
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 Irvine32.inc
.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 Irvine32.inc
.code
main PROC
call Clrscr
mov eax,15
call Delay
call DumpRegs
exit
main ENDP
END main
; clear screen first
; eax = 0000000F
; Display a null-terminated string and
; move the cursor to the beginning of the next screen
line.
INCLUDE Irvine32.inc
.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 Irvine32.inc
.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 Irvine32.inc
.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 1
•
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 2
•
•
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:
.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]
add ax, [MyWord + 2]
; d) ax:_____________________________
; e) ax:_____________________________
By Using PTR keywords, create and complete the following program
that can produce the following output based on given variables.
.data
varB BYTE 65h,31h,56h,65h
varW WORD 6543h,1202h
varD DWORD 87654321h
.code
mov _____________________
mov _____________________
mov _____________________
mov _____________________
mov _____________________
; answer : 6556h
; answer : 21h
; answer : 02h
; answer: 8765
; answer : 12026543h
• mov
• mov
• mov
• mov
• mov
ax,WORD PTR [varB+2]
bl,BYTE PTR varD
bl,BYTE PTR [varW+2]
ax,WORD PTR [varD+2]
eax,DWORD PTR varW
TITLE Add and Subtract, Version 2
INCLUDE Irvine32.inc
.data
val1
dword 10000h
val2
dword 40000h
val3
dword 0DDh
val4
dword 200h
finalVal dword ?
(AddSub2.asm)
.code
main PROC
add
add
sub
add
mov
Call
Exit
main ENDP
END main
eax,val1 ; start with 10000h
eax,val2 ; add 40000h
eax,val3 ; subtract 20000h
eax,val4
finalVal,eax
; store the result (30000h)
DumpRegs
; display the registers
TITLE mul binary and hexa, Version 2
INCLUDE Irvine32.inc
(mulbinhexa.asm)
.data
num1 dword 1111b
num2 dword 0Ah
finalnum dword ?
.code
main PROC
mov eax,num1
mov eax,num2
mul eax
mov finalnum,eax
call DumpRegs
exit
main ENDP
END main
; start 100b
; mul 11b
; store the result (12=C
; display the registers
Download