daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;  Comment block below must be filled out completely for each assignment
  2. ;  *************************************************************  
  3. ;  Student Name:  
  4. ;  COMSC-260 Spring 2019
  5. ;  Date:
  6. ;  Assignment #
  7. ;  Version of Visual Studio used 2017:  
  8. ;  Did program compile? Yes
  9. ;  Did program produce correct results? Yes
  10. ;  Is code formatted correctly including indentation, spacing and vertical alignment? Yes
  11. ;  Is every line of code commented? Yes
  12. ;
  13. ;  Estimate of time in hours to complete assignment: .5
  14. ;
  15. ;  In a few words describe the main challenge in writing this program: Getting used to shuffling memory to registers, without deleting any data
  16. ;  
  17. ;  Short description of what program does: evaluates eax = num2 - num1 + cx - bl + bh + edx, using the given values for each variable/register
  18. ;
  19. ;
  20. ;  *************************************************************
  21. ;  Reminder: each assignment should be the result of your
  22. ;  individual effort with no collaboration with other students.
  23. ;
  24. ;  Reminder: every line of code must be commented and formatted  
  25. ;  per the ProgramExpectations.pdf file on the class web site
  26. ; *************************************************************
  27.  
  28.  
  29. .386                   ;identifies minimum CPU for this program
  30.  
  31. .MODEL flat,stdcall    ;flat - protected mode program
  32.                        ;stdcall - enables calling of MS_windows programs
  33.  
  34. ;allocate memory for stack
  35. ;(default stack size for 32 bit implementation is 1MB without .STACK directive
  36. ;  - default works for most situations)
  37.  
  38. .STACK 4096            ;allocate 4096 bytes (1000h) for stack
  39.  
  40. ;*************************PROTOTYPES*****************************
  41.  
  42. ExitProcess PROTO,dwExitCode:DWORD  ;from Win32 api not Irvine
  43.  
  44. ReadChar PROTO                     ;Irvine code for getting a single char from keyboard
  45.                                    ;Character is stored in the al register.
  46.                                    ;Can be used to pause program execution until key is hit.
  47.  
  48.  
  49. WriteHex PROTO                      ;Irvine function to write a hex number in EAX to the console
  50.  
  51. WriteChar PROTO                     ;Irvine function to write a char in al to console
  52.  
  53. WriteString PROTO
  54.  
  55. ;************************DATA SEGMENT***************************
  56.  
  57. .data
  58.  
  59.     num1    dword   0CB7FB84h
  60.     num2    dword   0FFDD2547h
  61.     num3    dword   0C57h
  62.     num4    dword   5A9h
  63.     num5    dword   0B46Bh
  64.     num6    dword   0D3494h
  65.     num7    dword   1F514ABCh
  66.  
  67.     msgName    byte    "Program 2 by Luke Hentschel",0Ah,0
  68.     msgExit    byte    0Ah,"Hit any key to exit!",0
  69.  
  70. ;************************CODE SEGMENT****************************
  71.  
  72. .code
  73.  
  74. main PROC
  75.  
  76.     ;mov     ebx, 0BBBBFFFFh ;ebx = 0BBBBFFFFh
  77.     ;mov     eax, 0AAAAFFFFh ;eax = 0AAAAFFFFh
  78.     ;mov     ecx, 0CCCCFFFFh ;ecx = 0CCCCFFFFh
  79.     ;mov     edx, 0F5C8DEEDh ;edx = 0F5C8DEEDh
  80.     ;mov     bh,  11110110b  ;bh = 11110110b
  81.     ;mov     bl,  253d       ;bl = 253 (base 10)
  82.     ;mov     cx,  0FFB9h     ;cx = 0FFB9h
  83.  
  84.     ;;evaluate eax = num2 - num1 + cx - bl + bh + edx
  85.     ;movzx   eax, num2       ;eax = num2 (move to larger type)
  86.     ;movzx   esi, num1       ;esi = num1 (move to larger type)
  87.  
  88.     ;sub     eax, esi        ;eax = eax - esi (num2 - num1)
  89.  
  90.     ;movzx   ecx, cx         ;move cx to larger type
  91.     ;add     eax, ecx        ;eax = eax + ecx ((num2 - num1) + cx)
  92.  
  93.     ;;Now that cx has been used, use ecx to store bh
  94.     ;movzx   ecx, bh         ;move bh to larger type
  95.     ;movzx   ebx, bl         ;move bl to larger type (done second to ensure original bh is preserved)
  96.  
  97.     ;sub     eax, ebx        ;eax = eax - ebx ((num2 - num1 + cx) - bl)
  98.     ;add     eax, ecx        ;eax = eax + ecx ((num2 - num1 + cx - bl) + bh)
  99.     ;add     eax, edx        ;eax = eax + edx ((num2 - num1 + cx - bl + bh) + edx)
  100.  
  101.     ;evaluate num1 + num2 / (num3 * num4) - num5^2 % num6 + num7
  102.     ;order to evaluate in:
  103.     ;1. num5^2
  104.     ;2. num3 * num4
  105.     ;3. num2 / (step 2 result)
  106.     ;4. (step 1 result) % num6
  107.     ;5. num1 + (step 3 result)
  108.     ;6. (step 5 result) - (step 4 result)
  109.     ;7. (step 6 result) + num7
  110.  
  111.     mov     edx, offset msgName ; move msgName to edx for output
  112.     call    WriteString     ;output msgName
  113.  
  114.     mov     eax, num5       ;mov num5 to eax
  115.     mul     eax             ;square eax
  116.     mov     edi, eax        ;move num5^2 to edi
  117.     mov     ecx, eax        ;mov num5^2 to ecx (for output later)
  118.     mov     eax, num3       ;move num3 to eax
  119.     mul     num4            ;edx:eax = eax * num4
  120.     mov     esi, eax        ;move num3*num4 to esi
  121.     mov     eax, num2       ;move num2 to eax
  122.     div     esi             ;num2 / (num3 * num4)
  123.     mov     esi, eax        ;move quotient to esi
  124.     mov     eax, edi        ;move num5^2 to eax
  125.     mov     edx, 0          ;dividing edx:eax into num6 next line, must clear edx
  126.     div     num6            ;divide, modulus stored in edx
  127.    
  128.     mov     eax, num1       ;move num1 to eax
  129.     call    WriteHex        ;output num1 to console
  130.     add     eax, esi        ;add (num2 / (num3 * num4)) to num1
  131.     sub     eax, edx        ;subtract step 4 result from step 5 result
  132.     add     eax, num7       ;add num7 to previous result
  133.     mov     esi, eax        ;store result in esi
  134.    
  135.     mov     al, '+'         ;store '+' character in al
  136.     call    WriteChar       ;output '+' to console
  137.  
  138.     mov     eax, num2       ;move num2 to eax
  139.     call    WriteHex        ;output num2 to console
  140.  
  141.     mov     al, '/'         ;store '/' character in al
  142.     call    WriteChar       ;output '/' to console
  143.  
  144.     mov     al, '('         ;store '(' character in al
  145.     call    WriteChar       ;output '(' to console
  146.  
  147.     mov     eax, num3       ;mov num3 to eax
  148.     call    WriteHex        ;output num3 to console
  149.  
  150.     mov     al, '*'         ;store '*' in al
  151.     call    WriteChar       ;output '*' to console
  152.  
  153.     mov     eax, num4       ;mov num4 to eax
  154.     call    WriteHex        ;output num4 to console
  155.  
  156.     mov     al, ')'         ;store ')' char in al
  157.     call    WriteChar       ; output ')' char to console
  158.  
  159.     mov     al, '-'         ;store '-' char in al
  160.     call    WriteChar       ;output '-' to console
  161.  
  162.     mov     eax, ecx        ;mov num5^2 to eax for output
  163.     call    WriteHex        ;output num5^2
  164.  
  165.     mov     al, '%'         ;store '%' char in al
  166.     call    WriteChar       ;output '%'
  167.  
  168.     mov     eax, num6       ;mov num6 to eax for output
  169.     call    WriteHex        ;output num6 to console
  170.  
  171.     mov     al, '+'         ;store '+' char in al
  172.     call    WriteChar       ;output '+' to console
  173.  
  174.     mov     eax, num7       ;mov num7 to eax for output
  175.     call    WriteHex        ;output num7 to console
  176.  
  177.     mov     al, '='         ;store '=' char in al
  178.     call    WriteChar       ;output '=' to console
  179.  
  180.     mov     eax, esi        ;move result of arithmetic to eax for output
  181.  
  182.  
  183.  
  184.     call    WriteHex        ;output eax to console
  185.     mov     edx, offset msgExit ;move exit message to edx for WriteString
  186.     call    WriteString     ;output msgExit
  187.     call    ReadChar        ;Pause program execution while user inputs a non-displayed char
  188.     INVOKE  ExitProcess,0   ;exit to dos: like C++ exit(0)
  189.  
  190. main ENDP
  191. END main
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top