Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Comment block below must be filled out completely for each assignment
- ; *************************************************************
- ; Student Name:
- ; COMSC-260 Spring 2019
- ; Date:
- ; Assignment #
- ; Version of Visual Studio used 2017:
- ; Did program compile? Yes
- ; Did program produce correct results? Yes
- ; Is code formatted correctly including indentation, spacing and vertical alignment? Yes
- ; Is every line of code commented? Yes
- ;
- ; Estimate of time in hours to complete assignment: .5
- ;
- ; In a few words describe the main challenge in writing this program: Getting used to shuffling memory to registers, without deleting any data
- ;
- ; Short description of what program does: evaluates eax = num2 - num1 + cx - bl + bh + edx, using the given values for each variable/register
- ;
- ;
- ; *************************************************************
- ; Reminder: each assignment should be the result of your
- ; individual effort with no collaboration with other students.
- ;
- ; Reminder: every line of code must be commented and formatted
- ; per the ProgramExpectations.pdf file on the class web site
- ; *************************************************************
- .386 ;identifies minimum CPU for this program
- .MODEL flat,stdcall ;flat - protected mode program
- ;stdcall - enables calling of MS_windows programs
- ;allocate memory for stack
- ;(default stack size for 32 bit implementation is 1MB without .STACK directive
- ; - default works for most situations)
- .STACK 4096 ;allocate 4096 bytes (1000h) for stack
- ;*************************PROTOTYPES*****************************
- ExitProcess PROTO,dwExitCode:DWORD ;from Win32 api not Irvine
- ReadChar PROTO ;Irvine code for getting a single char from keyboard
- ;Character is stored in the al register.
- ;Can be used to pause program execution until key is hit.
- WriteHex PROTO ;Irvine function to write a hex number in EAX to the console
- WriteChar PROTO ;Irvine function to write a char in al to console
- WriteString PROTO
- ;************************DATA SEGMENT***************************
- .data
- num1 dword 0CB7FB84h
- num2 dword 0FFDD2547h
- num3 dword 0C57h
- num4 dword 5A9h
- num5 dword 0B46Bh
- num6 dword 0D3494h
- num7 dword 1F514ABCh
- msgName byte "Program 2 by Luke Hentschel",0Ah,0
- msgExit byte 0Ah,"Hit any key to exit!",0
- ;************************CODE SEGMENT****************************
- .code
- main PROC
- ;mov ebx, 0BBBBFFFFh ;ebx = 0BBBBFFFFh
- ;mov eax, 0AAAAFFFFh ;eax = 0AAAAFFFFh
- ;mov ecx, 0CCCCFFFFh ;ecx = 0CCCCFFFFh
- ;mov edx, 0F5C8DEEDh ;edx = 0F5C8DEEDh
- ;mov bh, 11110110b ;bh = 11110110b
- ;mov bl, 253d ;bl = 253 (base 10)
- ;mov cx, 0FFB9h ;cx = 0FFB9h
- ;;evaluate eax = num2 - num1 + cx - bl + bh + edx
- ;movzx eax, num2 ;eax = num2 (move to larger type)
- ;movzx esi, num1 ;esi = num1 (move to larger type)
- ;sub eax, esi ;eax = eax - esi (num2 - num1)
- ;movzx ecx, cx ;move cx to larger type
- ;add eax, ecx ;eax = eax + ecx ((num2 - num1) + cx)
- ;;Now that cx has been used, use ecx to store bh
- ;movzx ecx, bh ;move bh to larger type
- ;movzx ebx, bl ;move bl to larger type (done second to ensure original bh is preserved)
- ;sub eax, ebx ;eax = eax - ebx ((num2 - num1 + cx) - bl)
- ;add eax, ecx ;eax = eax + ecx ((num2 - num1 + cx - bl) + bh)
- ;add eax, edx ;eax = eax + edx ((num2 - num1 + cx - bl + bh) + edx)
- ;evaluate num1 + num2 / (num3 * num4) - num5^2 % num6 + num7
- ;order to evaluate in:
- ;1. num5^2
- ;2. num3 * num4
- ;3. num2 / (step 2 result)
- ;4. (step 1 result) % num6
- ;5. num1 + (step 3 result)
- ;6. (step 5 result) - (step 4 result)
- ;7. (step 6 result) + num7
- mov edx, offset msgName ; move msgName to edx for output
- call WriteString ;output msgName
- mov eax, num5 ;mov num5 to eax
- mul eax ;square eax
- mov edi, eax ;move num5^2 to edi
- mov ecx, eax ;mov num5^2 to ecx (for output later)
- mov eax, num3 ;move num3 to eax
- mul num4 ;edx:eax = eax * num4
- mov esi, eax ;move num3*num4 to esi
- mov eax, num2 ;move num2 to eax
- div esi ;num2 / (num3 * num4)
- mov esi, eax ;move quotient to esi
- mov eax, edi ;move num5^2 to eax
- mov edx, 0 ;dividing edx:eax into num6 next line, must clear edx
- div num6 ;divide, modulus stored in edx
- mov eax, num1 ;move num1 to eax
- call WriteHex ;output num1 to console
- add eax, esi ;add (num2 / (num3 * num4)) to num1
- sub eax, edx ;subtract step 4 result from step 5 result
- add eax, num7 ;add num7 to previous result
- mov esi, eax ;store result in esi
- mov al, '+' ;store '+' character in al
- call WriteChar ;output '+' to console
- mov eax, num2 ;move num2 to eax
- call WriteHex ;output num2 to console
- mov al, '/' ;store '/' character in al
- call WriteChar ;output '/' to console
- mov al, '(' ;store '(' character in al
- call WriteChar ;output '(' to console
- mov eax, num3 ;mov num3 to eax
- call WriteHex ;output num3 to console
- mov al, '*' ;store '*' in al
- call WriteChar ;output '*' to console
- mov eax, num4 ;mov num4 to eax
- call WriteHex ;output num4 to console
- mov al, ')' ;store ')' char in al
- call WriteChar ; output ')' char to console
- mov al, '-' ;store '-' char in al
- call WriteChar ;output '-' to console
- mov eax, ecx ;mov num5^2 to eax for output
- call WriteHex ;output num5^2
- mov al, '%' ;store '%' char in al
- call WriteChar ;output '%'
- mov eax, num6 ;mov num6 to eax for output
- call WriteHex ;output num6 to console
- mov al, '+' ;store '+' char in al
- call WriteChar ;output '+' to console
- mov eax, num7 ;mov num7 to eax for output
- call WriteHex ;output num7 to console
- mov al, '=' ;store '=' char in al
- call WriteChar ;output '=' to console
- mov eax, esi ;move result of arithmetic to eax for output
- call WriteHex ;output eax to console
- mov edx, offset msgExit ;move exit message to edx for WriteString
- call WriteString ;output msgExit
- call ReadChar ;Pause program execution while user inputs a non-displayed char
- INVOKE ExitProcess,0 ;exit to dos: like C++ exit(0)
- main ENDP
- END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement