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

Lab 2

The program calculates the arithmetic expression e=((a+b*c-d)/f+g*h)/i. It considers a, d, f as words and b, c, g, h, i as bytes. It converts the divisor f to double word to perform division. Only the quotient of divisions are of interest, with the result being a byte. It contains data declarations for the variables and performs the calculations using MASM instructions.

Uploaded by

Nelu Turcanu
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)
92 views

Lab 2

The program calculates the arithmetic expression e=((a+b*c-d)/f+g*h)/i. It considers a, d, f as words and b, c, g, h, i as bytes. It converts the divisor f to double word to perform division. Only the quotient of divisions are of interest, with the result being a byte. It contains data declarations for the variables and performs the calculations using MASM instructions.

Uploaded by

Nelu Turcanu
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/ 11

Ministerul Educației al Republicii Moldova

Universitatea Tehnică din Moldova


Facultatea de Calculatoare, Informatică și Microelectronică
Departamentul IS

REFERAT
Lucrare de laborator Nr 2
La disciplina “Arhitectura Calculatoarelor”

1. SCOPUL LUCRARII

Lucrarea prezinta instructiunile pentru transferuri de date, instructiuni in


aritmetica binara si in aritmetica BCD.
Codul din p.3.1 comentat:
INCLUDE Irvine32.inc
.data
alfa DW 3 DUP(?)
.code
main proc
mov ax,17 ; adresare indirecta a operandului sursa
mov ax,10101b ;
mov ax,11b ;
mov ax,21o ;
mov alfa,ax ; Adresare directa a operandului destinatie
mov cx,ax ; Interschimba registrele ax si bx
mov ax,bx ; Folosind registrul cx
mov ax,cx ;
xchg ax,bx ; Interschimba direct cele 2 registre.
mov si,2
mov alfa[si],ax ; Adresare relativa cu registrul si
mov esi,2
mov ebx,offset alfa ; Adresare imediata a operandului sursa
lea ebx,alfa ; Acelasi efect
mov ecx,[ebx][esi] ; Adresare bazata indexata a sursei
mov cx,alfa[2] ; Acelasi efect.
mov cx,[alfa+2] ; Acelasi efect
mov di,4
mov byte ptr [ebx][edi],55h ;
mov esi,2
mov ebx,3
mov alfa[ebx][esi],33h ; Adresare bazata indexata relativa a
; destinatiei
mov alfa[ebx+esi],33h ; Notatii echivalente
mov [alfa+ebx+esi],33h
mov [ebx][esi]+alfa,33h

exit
main ENDP
END main

Listingul acestui program


00000000 .data
00000000 00000003 [ alfa WORD 3 DUP(?)
0000
]

00000000 .code
00000000 main proc
00000000 66| B8 0011 mov ax,17
00000004 66| B8 0015 mov ax,10101b
00000008 66| B8 0003 mov ax,11b
0000000C 66| B8 0011 mov ax,21o
00000010 66| A3 mov alfa,ax
00000000 R
00000016 66| 8B C8 mov cx,ax
00000019 66| 8B C3 mov ax,bx
0000001C 66| 8B C1 mov ax,cx

0000001F 66| 93 xchg ax,bx


00000021 66| BE 0002 mov si,2
00000025 66| 89 04 35 mov alfa[si],ax
00000000 R
0000002D BE 00000002 mov esi,2
00000032 BB 00000000 R mov ebx,offset alfa
00000037 8D 1D 00000000 R lea ebx,alfa
0000003D 8B 0C 1E mov ecx,[ebx][esi]
00000040 66| 8B 0D mov cx,alfa[2]
00000002 R
00000047 66| 8B 0D mov cx,[alfa+2]
00000002 R
0000004E 66| BF 0004 mov di,4
00000052 C6 04 1F 55 mov byte ptr [ebx][edi],55h
00000056 BE 00000002 mov esi,2
0000005B BB 00000003 mov ebx,3
00000060 66| C7 84 1E mov alfa[ebx][esi],33h
00000000 R
0033
0000006A 66| C7 84 1E mov alfa[ebx+esi], 33h
00000000 R
0033
00000074 66| C7 84 1E mov [alfa+ebx+esi], 33h
00000000 R
0033
0000007E 66| C7 84 1E mov [ebx][esi]+alfa, 33h
00000000 R
0033
exit
00000088 6A 00 * push +000000000h
0000008A E8 00000000 E * call ExitProcess
0000008F main ENDP
END main

3.2. Sa se calculeze expresia aritmetica: e=((a+b*c-d)/f+g*h)/i.


INCLUDE Irvine32.inc

; Sa se calculeze expresia aritmetica: e=((a+b*c-d)/f+g*h)/i


; se considera a, d, f – cuvant b, c, g, h, i –byte
; ca sa putem executa impartirea cu f convertim impartitorul la dublucuvânt
; ne vor interesa doar caturile impartirilor, rezultatul va fi de tip octet

.data
a dw 5
b db 6
cd db 10
d dw 5
f dw 6
g db 10
h db 11
i db 10
interm dw ?
rez db ?

.code
main proc
mov eax,0
mov al, b
imul cd ; in ax avem b*c
add ax, a ; ax=b*c+a
sub ax, d ; ax=b*c+a-d
cwd ; am convertit cuvantul din ax, in dublu cuvantul , retinut in
dx:ax
idiv f ; obtinem câtul în ax si restul în dx ax=(a+b*c-d)/f
mov interm, ax ; interm=(a+b*c-d)/f
mov al, g
imul h ; ax=g*h
add ax, interm ; ax=(a+b*c-d)/f+g*h
idiv i ; se obtine catul în al si restul în ah
mov rez, al
exit
main ENDP
END main

Listingul programului:
00000000 .data
00000000 0005 a dw 5
00000002 06 b db 6
00000003 0A cd db 10
00000004 0005 d dw 5
00000006 0006 f dw 6
00000008 0A g db 10
00000009 0B h db 11
0000000A 0A i db 10
0000000B 0000 interm dw ?
0000000D 00 rez db ?

00000000 .code
00000000 main proc
00000000 B8 00000000 mov eax,0
00000005 A0 00000002 R mov al, b
0000000A F6 2D 00000003 R imul cd
00000010 66| 03 05 add ax, a ; ax=b*c+a
00000000 R
00000017 66| 2B 05 sub ax, d ; ax=b*c+a-d
00000004 R
0000001E 66| 99 cwd
00000020 66| F7 3D idiv f
00000006 R
00000027 66| A3 mov interm, ax
0000000B R
0000002D A0 00000008 R mov al, g
00000032 F6 2D 00000009 R imul h
00000038 66| 03 05 add ax, interm
0000000B R
0000003F F6 3D 0000000A R idiv i
00000045 A2 0000000D R mov rez, al

exit
0000004A 6A 00 * push +000000000h
0000004C E8 00000000 E * call ExitProcess
00000051 main ENDP
END main
Problema propusa:
15. z=((a+b*c-d)/f+h)/g

INCLUDE Irvine32.inc

.data
a dw 5
b db 6
cd db 10
d dw 5
f dw 6
g db 10
h db 11
i db 10
interm dw ?
rez db ?

.code
main proc
mov eax,0
mov al, b
imul cd ; in ax avem b*c
add ax, a ; ax=b*c+a
sub ax, d ; ax=b*c+a-d
cwd ; am convertit cuvantul din ax, in dublu cuvantul , retinut in
dx:ax
idiv f ; obtinem câtul în ax si restul în dx ax=(a+b*c-d)/f
mov interm, ax ; interm=(a+b*c-d)/f
mov al, g
imul h ; ax=g*h
add ax, interm ; ax=(a+b*c-d)/f+g*h
idiv i ; se obtine catul în al si restul în ah
mov rez, al

exit
main ENDP
END main

Debugging
Listing file
Microsoft (R) Macro Assembler Version 14.25.28614.0 05/19/20 17:48:44
pr3_2.asm Page 1 - 1

INCLUDE Irvine32.inc
C ; Include file for Irvine32.lib (Irvine32.inc)
C
C ;OPTION CASEMAP:NONE ; optional: make
identifiers case-sensitive
C
C INCLUDE SmallWin.inc ; MS-Windows prototypes,
structures, and constants
C .NOLIST
C .LIST
C
C INCLUDE VirtualKeys.inc
C ; VirtualKeys.inc
C .NOLIST
C .LIST
C
C
C .NOLIST
C .LIST
C

; Sa se calculeze expresia aritmetica: e=((a+b*c-


d)/f+g*h)/i
; se considera a, d, f – cuvant b, c, g, h, i –byte
; ca sa putem executa impartirea cu f convertim
impartitorul la dublucuvânt
; ne vor interesa doar caturile impartirilor,
rezultatul va fi de tip octet

00000000 .data
00000000 0005 a dw 5
00000002 06 b db 6
00000003 0A cd db 10
00000004 0005 d dw 5
00000006 0006 f dw 6
00000008 0A g db 10
00000009 0B h db 11
0000000A 0A i db 10
0000000B 0000 interm dw ?
0000000D 00 rez db ?

00000000 .code
00000000 main proc
00000000 B8 00000000 mov eax,0
00000005 A0 00000002 R mov al, b
0000000A F6 2D 00000003 R imul cd ; in ax avem b*c
00000010 66| 03 05 add ax, a ; ax=b*c+a
00000000 R
00000017 66| 2B 05 sub ax, d ; ax=b*c+a-d
00000004 R
0000001E 66| 99 cwd ; am convertit cuvantul din ax, in
dublu cuvantul , retinut in dx:ax
00000020 66| F7 3D idiv f ; obtinem câtul în ax si
restul în dx ax=(a+b*c-d)/f
00000006 R
00000027 66| A3 mov interm, ax ; interm=(a+b*c-d)/f
0000000B R
0000002D A0 00000008 R mov al, g
00000032 F6 2D 00000009 R imul h ; ax=g*h
00000038 66| 03 05 add ax, interm ; ax=(a+b*c-d)/f+g*h
0000000B R
0000003F F6 3D 0000000A R idiv i ; se obtine catul în al si
restul în ah
00000045 A2 0000000D R mov rez, al

exit
0000004A 6A 00 * push +000000000h
0000004C E8 00000000 E * call ExitProcess
00000051 main ENDP
END main
_Microsoft (R) Macro Assembler Version 14.25.28614.0 05/19/20 17:48:44

Concluzie:
In aceasta lucrare de laborator am invatat tipurile de tade al
microprocesorului, conversia numerelor in diferite baze. In
urma acesteea, a fost elaborat un program de calculare a unei
expresii matematice.

You might also like