الأربعاء، 20 يناير 2010

Assembly programs



بسم الله الرحمن الرحيم
السلام عليكم ورحمه الله وبركاته 
اصحابي الاعزاء دي  بعض برامج الاسمبلي علشان امتحان العملي بكره وان شاء الله هيكون سهل زي البرولوج وبالتوفيق للجميع
max program   
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall,dwExitCode:DWORD
include io.h
cr equ 0dh
lf equ 0ah
.STACK 4096
.DATA  
list           BYTE             10,30,1,90,4  
Result    Byte             "the maximum is:"
max       WORD   ?
  Byte cr,lf,0
.CODE 
_start:

  mov ecx,4
LEA  ebx,list
mov  AL,[ebx]
next:
  add ebx,1
  cmp    AL,[ebx]
  jge   skip
  mov   AL,[ebx]
skip:
  loop  next
  mov AH,0 
  Itoa  max,AH
  output    Result
INVOKE ExitProcess,0
PUBLIC _start
END  
ودي نتيجه التنفيذ




sum of N-series
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall,dwExitCode:DWORD
include io.h
cr equ 0dh
lf equ 0ah
.STACK 4096
.DATA
S     Byte        "enter the N series:"
N       Dword    ?
RES  Byte        "the sum is:",0
sum   Dword    ?,0
.CODE
_start:
          output S
          input N,4
          atod  N
          mov Ecx,Eax
          mov edx,0
next:
        add edx,ecx
        loop next
       dtoa sum,edx
       output RES
 output sum
INVOKE ExitProcess,0
PUBLIC _start
END



 search for an element in array
.386
.MODEL FLAT
.STACK  4096                 ; reserve 4096-byte stack
INCLUDE io.h


ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

.DATA                        ; reserve storage for data

list DWORD 13,12,10,30,40,50,60,70,80,9
msg1 BYTE  "enter number to be searched: ", 0
num BYTE 6 DUP(?)
msg2 BYTE "The element was not found",0
msg3 BYTE "The element found",0
Res BYTE 10 DUP(?),0

.CODE                         ; start of main program code

search PROC NEAR32
push ecx
push edx
push ebx
push esi
push ebp

mov ebp,esp
mov ecx,[ebp+28]              ; number of array elements
mov ebx,[ebp+24]                ;address of list[0]
mov edx,[ebp+32]                  ; number for search
;output msg1
mov esi,0
         
next:   cmp edx,[ebx]         
             JNZ  skip
            mov eax,esi
            ;output msg1  
            JMP break
skip:    ; output msg1
             inc esi
             add  ebx,4                 ; move to next item
loop next

mov eax,-1
break:   

pop ebp
pop esi
pop ebx
pop edx
pop ecx

RET   
search ENDP

_start:
          
             output msg1
             input num,6
             atod num              ;eax=num
                       
            ;mov eax,-1

            mov ecx,10
            lea ebx,list
            push eax          ;number for search
            push ecx           ; n elements
            push ebx          ; address of list[0]
          
            call search          
                 
                dtoa Res,eax
                output Res

                             
        INVOKE  ExitProcess, 0  ; exit with return code 0

PUBLIC _start                ; make entry point public
END
Any Service
ربنا يوفقنا جميعا بكره والسلام عليكم ورحمه الله وبركاته

ليست هناك تعليقات:

إرسال تعليق