Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void Exercicio1();
- // Somar o conteúdo de um array
- void Exercicio2();
- // Dados dos números A e B, se A > B então Variável C = 1, caso contrário C = 0;
- void Exercicio3();
- // Dados os termos da equação de bascará: A,B e C calcule o Delta
- void Exercicio4();
- // Dada uma tabela chamada Tabela1 com 10 elementos quaisquer grave na variável R maior valor da tabela.
- void Exercicio5();
- // Descobrir tamanho de uma string
- void Exercicio6();
- // Dada duas variáveis strings cujo a primeira chama se STR1 e esta com o valor “FACENS” cujo o tamanho é 6 caracteres.Faça a transferência de dados de STR1 para STR2.
- void Exercicio7();
- // Dado duas strings STR1 e STR2 faça a comparação das mesmas, se STR1 = STR2 então Variável R = 1 caso contrário R = 0
- void Exercicio8();
- // Data uma tabela chamada TabelaSort com 10 elementos, efetua a ordenação da mesma.(utilize o algoritmo bolha)
- void Exercicio9();
- // Dada uma string de tamanho qualquer, invertê-la
- void Exercicio10();
- // Criar um vetor com tamanho T, encontrar quantas vezes um número desejado D aparece no vetor;
- void Exercicio11();
- // Descobrir maior valor entre 3 variáveis
- void Exercicio12();
- // Contar as vogais em uma string
- void Exercicio13();
- // Fatorial
- void Exercicio14();
- // Testando Pilha
- void Exercicio15();
- int main() {
- Exercicio1();
- Exercicio2();
- Exercicio3();
- Exercicio4();
- Exercicio5();
- Exercicio6();
- Exercicio7();
- Exercicio8();
- Exercicio9();
- Exercicio10();
- Exercicio11();
- Exercicio12();
- Exercicio13();
- Exercicio14();
- Exercicio15();
- getchar();
- return 0;
- }
- void Exercicio15()
- {
- cout << "Exercicio 15" << endl;
- int a = 5, b = 4;
- int ultimo;
- __asm {
- push a
- push b
- pop eax
- pop eax
- mov ultimo, eax
- }
- cout << ultimo << endl;
- }
- void Exercicio14(){
- cout << "Exercicio 14" << endl;
- short total;
- __asm {
- mov bx, 6
- call proc_fact
- mov total, ax
- jmp fim
- proc_fact :
- cmp bl, 1
- jg do_calculation
- mov ax, 1
- ret
- do_calculation :
- dec bl
- call proc_fact
- inc bl
- mul bl; ax = al * bl
- ret
- fim:
- }
- cout << total << endl;
- }
- void Exercicio13()
- {
- cout << "Exercicio 13" << endl;
- int total;
- char s[8] = "PALAVRA";
- int tam = 7;
- __asm {
- lea eax, s
- xor ebx, ebx
- xor ecx, ecx
- looping :
- cmp ebx, 7
- je fim
- jmp compA
- proximo :
- add eax, 1
- add ebx, 1
- jmp looping
- compA :
- cmp[eax], 'A'
- je incrementa
- cmp[eax], 'a'
- je incrementa
- jmp compE
- compE :
- cmp[eax], 'E'
- je incrementa
- cmp[eax], 'e'
- je incrementa
- jmp compI
- compI :
- cmp[eax], 'I'
- je incrementa
- cmp[eax], 'i'
- je incrementa
- jmp compO
- compO :
- cmp[eax], 'O'
- je incrementa
- cmp[eax], 'o'
- je incrementa
- jmp compU
- compU :
- cmp[eax], 'U'
- je incrementa
- cmp[eax], 'u'
- je incrementa
- jmp proximo
- incrementa :
- add ecx, 1
- mov total, ecx
- jmp proximo
- fim :
- }
- cout << total << endl;
- }
- void Exercicio12()
- {
- cout << "Exercicio 12" << endl;
- int a = 3, b = -4, c = 1, maior;
- __asm {
- mov eax, a
- mov maior, eax
- compB :
- cmp eax, b
- jge compC
- mov eax, b
- mov maior, eax
- compC :
- cmp eax, c
- jge fim
- mov eax, c
- mov maior, eax
- fim :
- }
- cout << maior << endl;
- }
- void Exercicio11()
- {
- cout << "Exercicio 11" << endl;
- int v[29] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- int qtde, D = 1;
- __asm
- {
- xor eax, eax
- mov qtde, eax
- lea eax, v
- xor bx, bx
- xor edx, edx
- looping :
- cmp bx, 28
- je fim
- mov ecx, [eax]
- cmp ecx, D
- je aumenta
- incremento :
- add eax, 4
- inc bx
- jmp looping
- aumenta :
- inc edx
- jmp incremento
- fim :
- mov qtde, edx
- }
- cout << qtde << endl;
- }
- void Exercicio10()
- {
- cout << "Exercicio 10" << endl;
- int tam;
- char s[11] = "mensagem 1";
- __asm
- {
- lea eax, s
- xor ebx, ebx
- xor ecx, ecx
- mov tam, ecx
- looping :
- cmp[eax], '\0'
- je fim
- add ecx, 1
- add eax, 1
- jmp looping
- fim :
- mov tam, ecx
- ; achado o tamanho da string, é hora de învertê - la
- lea eax, s
- mov ebx, 0
- mov ecx, tam
- sub ecx, 1
- For2:
- cmp ebx, ecx
- jge fim2
- mov dl, [eax + ebx]
- add dl, [eax + ecx]
- mov[eax + ebx], dl
- sub dl, [eax + ecx]
- mov[eax + ecx], dl
- mov dl, [eax + ebx]
- sub dl, [eax + ecx]
- mov[eax + ebx], dl
- inc ebx
- sub ecx, 1
- jmp For2
- fim2 :
- }
- cout << s << endl;
- }
- void Exercicio9()
- {
- cout << "Exercicio 9" << endl;
- int v[] = { 9, 10, 8, 7, 6, 5, 4, 3, 2, 1 };
- int aux, i, flag = 1, tam = 10;
- __asm
- {
- inicio:
- lea eax, v
- mov ebx, flag
- cmp ebx, 1
- jne fim
- mov ebx, 0
- mov flag, ebx
- mov ecx, 0
- innerFor:
- mov i, ecx
- mov edx, tam
- add edx, -1
- cmp ecx, edx
- jge inicio
- mov edx, [eax + 4]
- cmp edx, [eax]
- jge incremento; Mudar aqui para trocar entre crescente / decrescente
- mov ecx, [eax]
- mov[eax], edx
- mov[eax + 4], ecx
- mov ebx, 1
- mov flag, ebx
- incremento :
- mov ecx, i
- inc ecx
- add eax, 4
- jmp innerFor
- fim :
- }
- for (int i = 0; i < 10; i++)
- {
- cout << v[i] << " ";
- }
- cout << endl;
- }
- void Exercicio8()
- {
- cout << "Exercicio 8" << endl;
- char s[7] = "FACENS";
- char s2[7] = "FACENS";
- int R;
- __asm
- {
- lea eax, s
- lea ebx, s2
- mov ecx, 1
- mov R, ecx
- looping :
- cmp[eax], '\0'
- je fim
- mov ecx, [eax]
- cmp ecx, [ebx]
- jne naoiguais
- add eax, 1
- add ebx, 1
- jmp looping
- naoiguais :
- mov ecx, 0
- mov R, ecx
- jmp fim
- fim :
- }
- cout << R << endl;
- }
- void Exercicio7()
- {
- cout << "Exercicio 7" << endl;
- char s[7] = "FACENS";
- char s2[7] = " ";
- __asm
- {
- lea eax, s
- lea ebx, s2
- looping :
- cmp[eax], '\0'
- je fim
- mov ecx, [eax]
- mov[ebx], ecx
- add ebx, 1
- add eax, 1
- jmp looping
- fim :
- }
- cout << s2 << endl;
- }
- void Exercicio6()
- {
- cout << "Exercicio 6" << endl;
- int tam;
- char s[] = "FACENSSSSSSSSSSS";
- __asm
- {
- lea eax, s
- xor ebx, ebx
- xor ecx, ecx
- mov tam, ecx
- looping :
- cmp[eax], '\0'
- je fim
- add ecx, 1
- add eax, 1
- jmp looping
- fim :
- mov tam, ecx
- }
- cout << tam << endl;
- }
- void Exercicio5()
- {
- cout << "Exercicio 5" << endl;
- int v[] = { 10, 2, 3, 4, -1, 6, 7, 8, 9, 10 };
- int R, menor;
- __asm
- {
- lea eax, v
- xor cx, cx
- mov edx, [eax]
- mov menor, edx
- add eax, 4
- looping:
- cmp cx, 9
- je fim
- mov edx, menor
- mov ebx, [eax]
- cmp[eax], edx
- jl troca
- jmp proximo
- troca :
- mov edx, [eax]
- mov menor, edx
- proximo :
- inc cx
- add eax, 4
- jmp looping
- fim :
- mov eax, menor
- mov R, eax
- }
- cout << R << endl;
- }
- void Exercicio4()
- {
- cout << "Exercicio 4" << endl;
- int A, B, C, delta, aux;
- A = 1;
- B = 4;
- C = 3;
- __asm
- {
- // Resultado do mul fica no EAX
- mov eax, B
- mul eax
- mov delta, eax
- mov eax, -4
- imul A
- imul C
- mov ebx, delta
- add eax, ebx
- mov delta, eax
- }
- cout << delta << endl;
- }
- void Exercicio3()
- {
- cout << "Exercicio 3" << endl;
- int A, B, C;
- A = 3;
- B = 2;
- __asm
- {
- mov eax, A
- mov ebx, B
- mov ecx, C
- cmp eax, ebx
- jg cum
- jmp czero
- cum :
- mov ecx, 1
- mov C, ecx
- jmp fim
- czero :
- mov ecx, 0
- mov C, ecx
- fim :
- }
- cout << C << endl;
- }
- void Exercicio2()
- {
- cout << "Exercicio 2" << endl;
- int vet[] = { 1, 5, 2, 6, 4, 1, 5, 2, 6, 4 }, s, aux;
- __asm
- {
- mov eax, 0
- mov s, eax
- xor cx, cx
- lea eax, vet
- looping :
- cmp cx, 10
- jge fim
- mov edx, [eax]
- mov aux, edx
- mov edx, s
- add edx, aux
- mov s, edx
- add eax, 4
- inc cx
- jmp looping
- fim :
- }
- cout << s << endl;
- }
- void Exercicio1()
- {
- cout << "Exercicio 1" << endl;
- /*int *a = new int(), *b = new int();
- *a = 5;
- *b = 10;*/
- int a = 5, b = 10;
- __asm
- {
- mov eax, a
- mov ecx, b
- push eax
- push ecx
- call troca
- pop b
- pop a
- jmp fim
- troca :
- push ebp
- mov ebp, esp
- push ebx
- push esi
- push edi
- mov eax, [ebp + 12]
- mov ecx, [ebp + 8]
- mov[ebp + 12], ecx
- mov[ebp + 8], eax
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
- fim :
- }
- printf("%d %d\n", a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement