# Arhitectura sistemelor de calcul

## Laboratoare

operand explicatie
m8, m16, m32 - locatie din memorie pe 8, 16 sau 32 biti
r8, r16, r32 - registru pe 8, 16 sau 32 biti
imm8, imm16, imm32 - valoare imediata pe 8, 16 sau 32 biti
• Laboratorul 3:
• Laboratorul 4:
• Laboratorul 5 - apel de funcții:
• Laboratorul 6 - Instrucțiuni de comparare, salt condiționat și ciclare. Operații pe șiruri:
• Laboratorul 7 - Operații pe șiruri
• suport teoretic
• exemplu
• probleme tema. Termen de predare temă: 1 săptămână.
• probleme de rezolvat în laborator:
1. Given two strings of words, a and b, obtain a third string c in the following way: concatenate the string of the least significant bytes from the words of the first string with the string of most significant bytes of the words from the second string. String c must be ordered ascending, bytes are signed numbers.

Example: let the two string be defined as
a dw 1234h,5678h,90h
b dw 4h,0abcdh,10h,1122h
c times 7 db 0
These two strings will be represented in memory:
a -> | 34h| 12h| 78h| 56h| 90h| 00h|
b -> | 04h| 00h| 0cdh| 0abh| 10h| 00h| 22h| 11h|
By concatenating, as required, string c will be:
34h,78h,90h,00h,0abh,00h,11h. After concatenating, string c must be ordered ascending.

2. Consider a string of double words. Obtain the ascending ordered sequence of bytes of rank multiple of 3 of the given string.

Example: let the double word string be
s dd 12345678h,5bcfh,45327h,1798dfeh,0f112233h
This string will be represented in memory as:
| 78h| 56h| 34h| 12h| 0cfh| 5bh| 00h| 00h| 27h| 53h| 04h| 00h| 0feh| 8dh| 79h| 01h| 33h| 22h| 11h| 0fh|
The sequence of bytes of rank multiple of 3 of the string s is obtained by concatenating the bytes from positions 0,3,6,9,..:
| 78h| 12h| 00h| 53h| 0feh| 01h| 11h|
This sequence must be in ascending order.

3. Brain teaser ;)
Consider a string of bytes, move the element of the string found at the highest address to the lowest address using only the instructions: cmp, jump instrunctions and simple arithmetic instructions (add, sub, adc and sbb).
Example, let string a be:
a db 'bcdefgha'
Your program shoud change string a in:
'abcdefgh'
• Laboratorul 9 - operații cu fișiere:
• suport teoretic
• exemple
• probleme tema. Termen de predare tema: 1 saptămână.
• probleme de rezolvat în laborator:
1. Write a program that reads a decimal number from the keyboard. The number is unsigned, the maximum number of digits before and after the decimal point is 4. Add the value of pi (3.1415) to this number and write the result in a file. The name of the file is also read from the keyboard.

Example:
Input number: 23.543
File name: result.txt
Outcome: the file result.txt will contain the string '26.6845'.

2. Read a number from keyboard, in hexadecimal format. Validate that it is between 0 and 0xFFFF (it should be represented on a word). If it's not, display a message and read the number again. Open a file named "in.txt", which should contain exactly 16 bytes. Read them, and then print on the screen only those characters whose corresponding bit index in the number read from the keyboard is set.

Example:
in.txt: 0123456789abcdef
output: 0579cdef
• Laboratorul 11 - programare multi-modul:
• Laboratorul 12
Solve the following problem:
1. Write a program that reads a string of maximum 100 bytes from the keyboard. Determine the number of digits in the string and write a procedure that prints this number in base 16 on the screen.

2. Write a program that reads the numbers a, b, and c and computes the expression a*b-c. This program should be devised into 2 modules, your main module M1 should:
• define the function ReadInteger that reads an integer number from the keyboard and returns this number; call the function ComputeExpr defined in module 2.

Module 2 should:

• define the function ComputeExpr that gets as parameters the numbers a and b, reads the number c (by calling function ReadInteger from module 1), computes the expression a*b-c and returns the result.

• Reguli predare teme!!