Advertisement
huberemanuel

estudos-arquitetura

Sep 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Exercicio1();
  6. // Somar o conteúdo de um array
  7. void Exercicio2();
  8. // Dados dos números A e B, se A > B então Variável C = 1, caso contrário C = 0;
  9. void Exercicio3();
  10. // Dados os termos da equação de bascará: A,B e C calcule o Delta
  11. void Exercicio4();
  12. // Dada uma tabela chamada Tabela1 com 10 elementos quaisquer grave na variável R maior valor da tabela.
  13. void Exercicio5();
  14. // Descobrir tamanho de uma string
  15. void Exercicio6();
  16. // 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.
  17. void Exercicio7();
  18. // 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
  19. void Exercicio8();
  20. // Data uma tabela chamada TabelaSort com 10 elementos, efetua a ordenação da mesma.(utilize o algoritmo bolha)
  21. void Exercicio9();
  22. // Dada uma string de tamanho qualquer, invertê-la
  23. void Exercicio10();
  24. // Criar um vetor com tamanho T, encontrar quantas vezes um número desejado D aparece no vetor;
  25. void Exercicio11();
  26. // Descobrir maior valor entre 3 variáveis
  27. void Exercicio12();
  28. // Contar as vogais em uma string
  29. void Exercicio13();
  30. // Fatorial
  31. void Exercicio14();
  32. // Testando Pilha
  33. void Exercicio15();
  34.  
  35. int main() {
  36.  
  37.     Exercicio1();
  38.     Exercicio2();
  39.     Exercicio3();
  40.     Exercicio4();
  41.     Exercicio5();
  42.     Exercicio6();
  43.     Exercicio7();
  44.     Exercicio8();
  45.     Exercicio9();
  46.     Exercicio10();
  47.     Exercicio11();
  48.     Exercicio12();
  49.     Exercicio13();
  50.     Exercicio14();
  51.     Exercicio15();
  52.  
  53.     getchar();
  54.  
  55.     return 0;
  56. }
  57.  
  58. void Exercicio15()
  59. {
  60.     cout << "Exercicio 15" << endl;
  61.  
  62.     int a = 5, b = 4;
  63.     int ultimo;
  64.  
  65.     __asm {
  66.         push a
  67.         push b
  68.         pop eax
  69.         pop eax
  70.         mov ultimo, eax
  71.     }
  72.  
  73.     cout << ultimo << endl;
  74. }
  75.  
  76. void Exercicio14(){
  77.  
  78.     cout << "Exercicio 14" << endl;
  79.  
  80.     short total;
  81.  
  82.     __asm {
  83.         mov bx, 6
  84.             call  proc_fact
  85.             mov total, ax
  86.             jmp fim
  87.  
  88.         proc_fact :
  89.             cmp   bl, 1
  90.             jg    do_calculation
  91.             mov   ax, 1
  92.             ret
  93.  
  94.         do_calculation :
  95.         dec   bl
  96.             call  proc_fact
  97.             inc   bl
  98.             mul   bl; ax = al * bl
  99.             ret
  100.  
  101.         fim:
  102.     }
  103.  
  104.     cout << total << endl;
  105.  
  106. }
  107. void Exercicio13()
  108. {
  109.     cout << "Exercicio 13" << endl;
  110.     int total;
  111.     char s[8] = "PALAVRA";
  112.     int tam = 7;
  113.  
  114.     __asm {
  115.         lea eax, s
  116.             xor ebx, ebx
  117.             xor ecx, ecx
  118.  
  119.         looping :
  120.         cmp ebx, 7
  121.             je fim
  122.             jmp compA
  123.         proximo :
  124.         add eax, 1
  125.             add ebx, 1
  126.             jmp looping
  127.  
  128.         compA :
  129.         cmp[eax], 'A'
  130.             je incrementa
  131.             cmp[eax], 'a'
  132.             je incrementa
  133.             jmp compE
  134.  
  135.         compE :
  136.         cmp[eax], 'E'
  137.             je incrementa
  138.             cmp[eax], 'e'
  139.             je incrementa
  140.             jmp compI
  141.  
  142.         compI :
  143.         cmp[eax], 'I'
  144.             je incrementa
  145.             cmp[eax], 'i'
  146.             je incrementa
  147.             jmp compO
  148.  
  149.         compO :
  150.         cmp[eax], 'O'
  151.             je incrementa
  152.             cmp[eax], 'o'
  153.             je incrementa
  154.             jmp compU
  155.  
  156.         compU :
  157.         cmp[eax], 'U'
  158.             je incrementa
  159.             cmp[eax], 'u'
  160.             je incrementa
  161.             jmp proximo
  162.  
  163.         incrementa :
  164.         add ecx, 1
  165.             mov total, ecx
  166.             jmp proximo
  167.  
  168.         fim :
  169.     }
  170.  
  171.     cout << total << endl;
  172. }
  173.  
  174. void Exercicio12()
  175. {
  176.     cout << "Exercicio 12" << endl;
  177.  
  178.     int a = 3, b = -4, c = 1, maior;
  179.  
  180.     __asm {
  181.         mov eax, a
  182.             mov maior, eax
  183.  
  184.         compB :
  185.         cmp eax, b
  186.             jge compC
  187.             mov eax, b
  188.             mov maior, eax
  189.  
  190.         compC :
  191.         cmp eax, c
  192.             jge fim
  193.             mov eax, c
  194.             mov maior, eax
  195.         fim :
  196.     }
  197.  
  198.     cout << maior << endl;
  199. }
  200.  
  201. void Exercicio11()
  202. {
  203.     cout << "Exercicio 11" << endl;
  204.  
  205.     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 };
  206.     int qtde, D = 1;
  207.  
  208.     __asm
  209.     {
  210.         xor eax, eax
  211.             mov qtde, eax
  212.             lea eax, v
  213.             xor bx, bx
  214.             xor edx, edx
  215.  
  216.         looping :
  217.         cmp bx, 28
  218.             je fim
  219.             mov ecx, [eax]
  220.             cmp ecx, D
  221.             je aumenta
  222.         incremento :
  223.         add eax, 4
  224.             inc bx
  225.             jmp looping
  226.  
  227.         aumenta :
  228.         inc edx
  229.             jmp incremento
  230.  
  231.         fim :
  232.         mov qtde, edx
  233.     }
  234.  
  235.     cout << qtde << endl;
  236. }
  237.  
  238. void Exercicio10()
  239. {
  240.     cout << "Exercicio 10" << endl;
  241.  
  242.     int tam;
  243.  
  244.     char s[11] = "mensagem 1";
  245.  
  246.     __asm
  247.     {
  248.         lea eax, s
  249.             xor ebx, ebx
  250.             xor ecx, ecx
  251.             mov tam, ecx
  252.  
  253.         looping :
  254.         cmp[eax], '\0'
  255.             je fim
  256.             add ecx, 1
  257.             add eax, 1
  258.             jmp looping
  259.  
  260.         fim :
  261.         mov tam, ecx
  262.  
  263.             ; achado o tamanho da string, é hora de învertê - la
  264.  
  265.             lea eax, s
  266.             mov ebx, 0
  267.             mov ecx, tam
  268.             sub ecx, 1
  269.  
  270.         For2:
  271.         cmp ebx, ecx
  272.             jge fim2
  273.             mov dl, [eax + ebx]
  274.             add dl, [eax + ecx]
  275.             mov[eax + ebx], dl
  276.             sub dl, [eax + ecx]
  277.             mov[eax + ecx], dl
  278.             mov dl, [eax + ebx]
  279.             sub dl, [eax + ecx]
  280.             mov[eax + ebx], dl
  281.             inc ebx
  282.             sub ecx, 1
  283.             jmp For2
  284.  
  285.         fim2 :
  286.     }
  287.  
  288.     cout << s << endl;
  289. }
  290.  
  291. void Exercicio9()
  292. {
  293.     cout << "Exercicio 9" << endl;
  294.     int v[] = { 9, 10, 8, 7, 6, 5, 4, 3, 2, 1 };
  295.     int aux, i, flag = 1, tam = 10;
  296.  
  297.     __asm
  298.     {
  299.     inicio:
  300.         lea eax, v
  301.             mov ebx, flag
  302.             cmp ebx, 1
  303.             jne fim
  304.             mov ebx, 0
  305.             mov flag, ebx
  306.  
  307.             mov ecx, 0
  308.         innerFor:
  309.         mov i, ecx
  310.             mov edx, tam
  311.             add edx, -1
  312.             cmp ecx, edx
  313.             jge inicio
  314.             mov edx, [eax + 4]
  315.             cmp edx, [eax]
  316.             jge incremento; Mudar aqui para trocar entre crescente / decrescente
  317.             mov ecx, [eax]
  318.             mov[eax], edx
  319.             mov[eax + 4], ecx
  320.             mov ebx, 1
  321.             mov flag, ebx
  322.         incremento :
  323.         mov ecx, i
  324.             inc ecx
  325.             add eax, 4
  326.             jmp innerFor
  327.  
  328.         fim :
  329.     }
  330.  
  331.     for (int i = 0; i < 10; i++)
  332.     {
  333.         cout << v[i] << " ";
  334.     }
  335.     cout << endl;
  336. }
  337.  
  338. void Exercicio8()
  339. {
  340.     cout << "Exercicio 8" << endl;
  341.  
  342.     char s[7] = "FACENS";
  343.     char s2[7] = "FACENS";
  344.     int R;
  345.  
  346.     __asm
  347.     {
  348.         lea eax, s
  349.             lea ebx, s2
  350.             mov ecx, 1
  351.             mov R, ecx
  352.  
  353.         looping :
  354.         cmp[eax], '\0'
  355.             je fim
  356.             mov ecx, [eax]
  357.             cmp ecx, [ebx]
  358.             jne naoiguais
  359.             add eax, 1
  360.             add ebx, 1
  361.             jmp looping
  362.  
  363.         naoiguais :
  364.         mov ecx, 0
  365.             mov R, ecx
  366.             jmp fim
  367.  
  368.         fim :
  369.     }
  370.  
  371.     cout << R << endl;
  372. }
  373.  
  374. void Exercicio7()
  375. {
  376.     cout << "Exercicio 7" << endl;
  377.  
  378.     char s[7] = "FACENS";
  379.     char s2[7] = "      ";
  380.  
  381.     __asm
  382.     {
  383.         lea eax, s
  384.             lea ebx, s2
  385.  
  386.         looping :
  387.         cmp[eax], '\0'
  388.             je fim
  389.             mov ecx, [eax]
  390.             mov[ebx], ecx
  391.             add ebx, 1
  392.             add eax, 1
  393.             jmp looping
  394.  
  395.         fim :
  396.     }
  397.  
  398.     cout << s2 << endl;
  399. }
  400.  
  401. void Exercicio6()
  402. {
  403.     cout << "Exercicio 6" << endl;
  404.  
  405.     int tam;
  406.  
  407.     char s[] = "FACENSSSSSSSSSSS";
  408.  
  409.     __asm
  410.     {
  411.         lea eax, s
  412.             xor ebx, ebx
  413.             xor ecx, ecx
  414.             mov tam, ecx
  415.  
  416.         looping :
  417.         cmp[eax], '\0'
  418.             je fim
  419.             add ecx, 1
  420.             add eax, 1
  421.             jmp looping
  422.  
  423.         fim :
  424.         mov tam, ecx
  425.     }
  426.  
  427.     cout << tam << endl;
  428. }
  429.  
  430. void Exercicio5()
  431. {
  432.     cout << "Exercicio 5" << endl;
  433.  
  434.     int v[] = { 10, 2, 3, 4, -1, 6, 7, 8, 9, 10 };
  435.     int R, menor;
  436.  
  437.     __asm
  438.     {
  439.         lea eax, v
  440.             xor cx, cx
  441.             mov edx, [eax]
  442.             mov menor, edx
  443.             add eax, 4
  444.  
  445.         looping:
  446.         cmp cx, 9
  447.             je fim
  448.             mov edx, menor
  449.             mov ebx, [eax]
  450.             cmp[eax], edx
  451.             jl troca
  452.             jmp proximo
  453.         troca :
  454.         mov edx, [eax]
  455.             mov menor, edx
  456.         proximo :
  457.         inc cx
  458.             add eax, 4
  459.             jmp looping
  460.  
  461.         fim :
  462.         mov eax, menor
  463.             mov R, eax
  464.     }
  465.  
  466.     cout << R << endl;
  467. }
  468.  
  469. void Exercicio4()
  470. {
  471.     cout << "Exercicio 4" << endl;
  472.     int A, B, C, delta, aux;
  473.     A = 1;
  474.     B = 4;
  475.     C = 3;
  476.  
  477.     __asm
  478.     {
  479.         // Resultado do mul fica no EAX
  480.         mov eax, B
  481.             mul eax
  482.             mov delta, eax
  483.  
  484.             mov eax, -4
  485.             imul A
  486.             imul C
  487.  
  488.             mov ebx, delta
  489.             add eax, ebx
  490.             mov delta, eax
  491.     }
  492.  
  493.     cout << delta << endl;
  494. }
  495.  
  496. void Exercicio3()
  497. {
  498.     cout << "Exercicio 3" << endl;
  499.     int A, B, C;
  500.     A = 3;
  501.     B = 2;
  502.  
  503.     __asm
  504.     {
  505.         mov eax, A
  506.             mov ebx, B
  507.             mov ecx, C
  508.             cmp eax, ebx
  509.             jg cum
  510.             jmp czero
  511.  
  512.         cum :
  513.         mov ecx, 1
  514.             mov C, ecx
  515.             jmp fim
  516.         czero :
  517.         mov ecx, 0
  518.             mov C, ecx
  519.  
  520.         fim :
  521.     }
  522.  
  523.     cout << C << endl;
  524.  
  525. }
  526.  
  527. void Exercicio2()
  528. {
  529.     cout << "Exercicio 2" << endl;
  530.     int vet[] = { 1, 5, 2, 6, 4, 1, 5, 2, 6, 4 }, s, aux;
  531.  
  532.     __asm
  533.     {
  534.         mov eax, 0
  535.             mov s, eax
  536.             xor cx, cx
  537.             lea eax, vet
  538.  
  539.         looping :
  540.         cmp cx, 10
  541.             jge fim
  542.             mov edx, [eax]
  543.             mov aux, edx
  544.             mov edx, s
  545.             add edx, aux
  546.             mov s, edx
  547.             add eax, 4
  548.             inc cx
  549.             jmp looping
  550.  
  551.         fim :
  552.     }
  553.  
  554.     cout << s << endl;
  555. }
  556.  
  557. void Exercicio1()
  558. {
  559.     cout << "Exercicio 1" << endl;
  560.     /*int *a = new int(), *b = new int();
  561.     *a = 5;
  562.     *b = 10;*/
  563.     int a = 5, b = 10;
  564.  
  565.     __asm
  566.     {
  567.         mov eax, a
  568.             mov ecx, b
  569.             push eax
  570.             push ecx
  571.             call troca
  572.             pop b
  573.             pop a
  574.             jmp fim
  575.  
  576.         troca :
  577.         push ebp
  578.             mov ebp, esp
  579.             push ebx
  580.             push esi
  581.             push edi
  582.  
  583.             mov eax, [ebp + 12]
  584.             mov ecx, [ebp + 8]
  585.             mov[ebp + 12], ecx
  586.             mov[ebp + 8], eax
  587.  
  588.             pop edi
  589.             pop esi
  590.             pop ebx
  591.             pop ebp
  592.             ret
  593.         fim :
  594.  
  595.     }
  596.  
  597.     printf("%d %d\n", a, b);
  598.  
  599. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement