Vous êtes sur la page 1sur 8

Assignment 3A - A program that adds and subtracts 32-bit

numbers

After installing the assembler on the computer, enter the following program,
save it, assemble it and run it. Do not forget to add a comment with your
name in it.

You will hand in a listing (e.g., addsum.asm) that should include your name

TITLE Add and Subtract (AddSum.asm)


;This program adds and subtracts 32-bit integers

; Caterina Pentcheva
INCLUDE Irvine32.inc
.code
main PROC
mov eax, 10000h ; EAX = 10000h
add eax, 40000h ; EAX = 50000h
sub eax, 20000h ; EAX = 30000h
call DumpRegs ; display registers

exit
main ENDP
END main
My Source:

; Add and Subtract(AddSum.asm)


;This program adds and subtracts 32-bit integers
;Assignment: 3A
;Name: Joseph Wilcox
; assignment complete

INCLUDE Irvine32.inc

.code

main PROC

mov eax, 10000h ;EAX=10000h


add eax, 40000h ;EAX=50000h
sub eax, 20000h ;EAX=30000h
call DumpRegs ;display registers
exit
main ENDP
END main
Assignment 3B: Adding 4 32-Bit Integer Variables

The program will contain four 32-bit integer variables and add these
values together, saving the result in a variable. The sum should still be in
the EAX register when you call the library routine DumpRegs.

Have your values initialized in the data segment.

My Source:

; Add and Sum Variables(AddVarSum.asm)


;This program adds and sums variables of 32-bit integers
;Assignment: 3B
;Name:Joseph Wilcox
;assignment complete

INCLUDE Irvine32.inc

.data
val1 DWORD 20 ;32-bit usigned integer
val2 DWORD 28 ;32-bit usigned integer
val3 DWORD 36 ;32-bit usigned integer
val4 DWORD 42 ;32-bit usigned integer
sum DWORD 0 ;32-bit usigned integer

.code
main PROC
mov eax, val1 ;EAX=val1(20)
add eax, val2 ;EAX=eax(20)+val2(28), 48
add eax, val3 ;EAX=eax(48)+val3(36), 84
add eax, val4 ;EAX=eax(84)+val4(42), 126, 7E in hex
mov sum, eax ;move EAX(126) into var sum
call DumpRegs ;display registers

exit
main ENDP
END main
Assignment 3C: Answer the following questions
Question 1.

a. Declare a 32-bit signed integer variable and initialize it with the smallest
possible negative decimal value.

varSmallestNeg SDWORD -2147483648 ;p.79

b. Declare an uninitialized array of 100 16-bit unsigned integers.

iArray WORD 100 DUP(?)

c. Declare a string variable containing the word “DVC” repeated 20 times,


and terminated with the null char.

strVar BYTE DUP(‘DVC’),0

Question 2

For the following declarations, assuming that the address of I is 404000h

a. What are the addresses of J, K, and L?


J: 404002h
K: 404006h
L: 40400Ah

b. What is the total number of allocated bytes?


2xSBYTE=2+2xSWORD=4+DWORD=4+BYTE*3=3
2+4+4+3=13
13 Bytes allocated.
c. Show the content of the individual bytes allocated in memory in
hexadecimal
404000h:01
404001h:FF
404002h:FF
404003h:10
404004h:00
404005h:FF
404006h:56
404007h:34
404008h:02
404009h:00
40400Ah:43
40400Bh:56
40400Ch:44

.DATA

I SBYTE 1, -1

J SWORD 10FFh, -256

K DWORD 23456h

L BYTE 'DVC'

Question 3

Given the following definitions:

.DATA

wval LABEL WORD

barray BYTE 10h, 20h, 30h, 6 DUP (0Ah)

ALIGN 4

warray WORD 5 DUP (1000h)

pressKey EQU <"Press any key to continue ...", 0>

darray DWORD 5 DUP (56789ABh), 7 DUP (12345678h)

dval LABEL DWORD

prompt BYTE pressKey

What will be the value of EAX, AX, and AL after executing each of the
following instructions? Assume that the address of barray is 404000h.
a. mov eax, TYPE warray
EAX:00000002h
AX: 0002h
AL: 02h

b. mov eax, LENGTHOF barray


EAX:00000009h
AX: 0009h
AL: 09h

c. mov eax, SIZEOF darray


EAX:00000030h
AX: 0030h
AL: 30h

d. mov eax, OFFSET warray


EAX:0040400Ch
AX: 400Ch
AL: 0Ch

e. mov eax, OFFSET darray


EAX: 00404016h
AX: 4016h
AL:16h

f. mov eax, OFFSET prompt


EAX:00404046h
AX: 4046h
AL:46h

g. mov eax, DWORD PTR barray


EAX:0A302010h
AX: 2010h
AL:10h

h. mov al, BYTE PTR darray


EAX:0A3020ABh
AX: 20ABh
AL:ABh
i. mov ax, wval
EAX:0A302010h
AX: 2010h
AL:10h

j. mov eax, dval


EAX:73657250h
AX: 7250h
AL:50h

Vous aimerez peut-être aussi