본문 바로가기
코스웨어/13년 스마트컨트롤러

어셈블리 과제 _ 김성엽

by 알 수 없는 사용자 2013. 8. 28.
728x90
반응형

 소스

  

 = > 2(-x + y - 1) + z 


.386

.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

include io.h

cr  equ  0dh
Lf  equ  0ah

.STACK  4096

.DATA
Prompt1  BYTE  "This program will evaluate the expression", cr,Lf,Lf
         BYTE  "    2(-x + y - 1) + z", cr,Lf,Lf
         BYTE  "for your choice of integer values.", cr,Lf,Lf
         BYTE  "Enter value for x:  "0
Prompt2  BYTE  "Enter value for y:  "0
Prompt3  BYTE  "Enter value for z:  "0
Value    BYTE  16  DUP  (?)
Answer   BYTE  cr,Lf,"The result is "
Result   BYTE  6  DUP  (?)
         BYTE  cr,Lf, 0

.CODE
_start:
      output  Prompt1
      input  Value, 16
      atod  Value
      mov  dx,ax  ;x
      neg  dx  ;-x  

      output  Prompt2
      input  Value, 16
      atod  Value

      add  dx,ax  ;-x+y

      dec  dx  ;-x+y-1

      add  dx,dx  ;2*(-x+y-1)


      output  Prompt3

      input  Value, 16

      atod  Value

      add  dx,ax  ;2*(-x+y-1)+z


      itoa  Result,dx

  
      output  Answer


      INVOKE  ExitProcess, 0


PUBLIC  _start
END


------------ Source ------------

evalu_2.asm

--------------------------------



 4장 4.14

 .386

.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

INCLUDE io.h

cr   EQU   0dh 
LF   EQU   0ah 

.STACK 4096 

.DATA 
Prompt1  BYTE "This program will find the area of a rectangle",cr,Lf,Lf
         BYTE "Width of rectangle? ",0
Prompt2  BYTE "Length of rectangle? ",0
Value    BYTE   16   DUP (?)
Answer   BYTE cr,Lf,"The area of the rectangle is "
Area     BYTE 11 DUP (?)
         BYTE cr,Lf,0
.CODE 
_start:
Prompt:   output Prompt1 
          input  Value,16 
          atod   Value 

          mov    ebx,eax 

          output Prompt2 

          input  Value,16 

          atod   Value

          mul    ebx

          dtoa   Area,eax

          output Answer 

          INVOKE ExitProcess, 0 

PUBLIC _start 
END


 


------- Source ------ 

chap4_14.asm

---------------------




 4장 4.3.2 문제

;Write a complete 80x86 assembly language program to prompt for the
;length, width, and height of a box and to display its surface area
;2*(length*width + length*height + width*height).

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

include io.h

cr  equ  0dh
Lf  equ  0ah

.STACK  4096

.DATA
Prompt1  BYTE  "This program will evaluate the expression", cr,Lf,Lf
         BYTE  "    2*(length*width + length*height + width*height)", cr,Lf,Lf
         BYTE  "for your choice of integer values.", cr,Lf,Lf

         BYTE  "Enter value for x:  "0

Prompt2  BYTE  "Enter value for y:  "0
Prompt3  BYTE  "Enter value for z:  "0
Value    BYTE  16  DUP  (?)
Answer   BYTE  cr,Lf,"The result is "
Result   BYTE  6  DUP  (?)
         BYTE  cr,Lf, 0

.CODE
_start:
         output  Prompt1
         input  Value, 16

         atod  Value

         mov  ebx, eax  ; ebx = length

    
         output  Prompt2

         input  Value, 16

         atod  Value

         mov  ecx, eax  ; ecx = width


         output  Prompt3

         input  Value, 16

         atod  Value

         mov  edx, eax  ; edx = height, eax = height

  
         imul  edx, ebx  ; edx = length*height

         imul  eax, ecx  ; eax = width*height  

         imul  ebx, ecx  ; ebx = length*width


         add  edx, eax  

         add  ebx, edx  ; ebx = length*width+width*height+length*height

  
         shl  ebx, 1    ; 2*ebx


         dtoa  Result,ebx

  
         output  Answer


         INVOKE  ExitProcess, 0


PUBLIC  _start 

END


------- Source -------

chap4_2.asm

----------------------




728x90