Coding. INCLUDE Irvine32.inc.data Uarray WORD 1000h,2000h,3000h,4000h.code main PROC ; Move with...

Preview:

Citation preview

Coding

INCLUDE Irvine32.inc.dataUarray WORD 1000h,2000h,3000h,4000h

.codemain PROC

; Move with zero extension:movzx eax,Uarraymovzx ebx,Uarray+2movzx ecx,Uarray+4movzx edx,Uarray+6

call DumpRegsexit

main ENDPEND main

MOVZX

MOVSX

INCLUDE Irvine32.inc.dataSarray SWORD -1,-2,-3,-4

.codemain PROC

; Move with sign extension:;movsx eax,Sarray;movsx ebx,Sarray+2;movsx ecx,Sarray+4;movsx edx,Sarray+6

call DumpRegsexit

main ENDPEND main

INCLUDE irvine32.inc.codemain PROC

mov ax,15 ; start ax=15call DumpRegsmov ecx,6 ; set start ecx = 6

L1: ; L1 = destinationdec axcall DumpRegsloop L1

exitmain ENDPEND main

LOOP

INCLUDE Irvine32.inc.codemain PROC

mov eax, 1 ;start eax=1mov ebx, 1 ;ebx = 1mov edx, 10 ;edx = 10mov ecx, 6 ;loop ecx = 7 times ..6 5 4 3 2 1 0call DumpRegs

L2:inc ebxdec edxadd eax, 1 ; add value in eax + 1call DumpRegsloop L2

exitmain ENDPEND main

LOOP

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.datastr1 BYTE "This line is displayed in color",0.codemain PROC

mov eax, white + (green * 16) ; white on green backgrouund

mov ecx,4 ; loop counterL1: call SetTextColor

mov edx,OFFSET str1call WriteStringcall Crlfadd eax,2 ; add 2 to foreground color

loop L1exit

main ENDPEND main

Print output to screen

INCLUDE Irvine32.inc.codemain PROC

mov eax,1234h ; input argumentcall WriteHex; show hex numbercall Crlf ; end of line

; no call DumpRegs bcoz no register to be display

exitmain ENDPEND main

Clear screen before print output

; print outputINCLUDE Irvine32.inc.codemain PROC

call Clrscr ; clear screen firstmov eax,15 ; eax = 0000000Fcall Delaycall DumpRegs

exitmain ENDPEND main

; Display a null-terminated string and ; move the cursor to the beginning of the next screen

line.

INCLUDE Irvine32.inc.datastr1 BYTE "Assembly language is easy!",0.codemain PROC

mov edx,OFFSET str1call WriteStringcall Crlfexit

main ENDPEND 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.datastr1 BYTE "Assembly language is easy!",0Dh,0Ah,0str2 BYTE "I like Assembly language!",0Dh,0Ah,0.codemain PROC

mov edx,OFFSET str1call WriteStringcall Crlfcall Crlf

mov edx,OFFSET str2call WriteString

exitmain ENDPEND main

Display an unsigned integer in binary, decimal, and hexadecimal, each on a separate line.

INCLUDE Irvine32.inc.dataIntVal = 35.codemain PROC

mov eax,IntValcall WriteBin ; display binarycall Crlf

call WriteDec; display decimalcall Crlf

call WriteHex; display hexadecimalcall Crlf

exitmain ENDPEND 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] ; 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.

 

 .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 (AddSub2.asm)

INCLUDE Irvine32.inc

 .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 (mulbinhexa.asm)

INCLUDE Irvine32.inc

.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

Recommended