Формирование массива из 10 двухбайтных чисел; переписать во второй массив все отрицательные числа

Страницы работы

5 страниц (Word-файл)

Содержание работы

   Задание: Сформировать массив из 10 двухбайтных чисел. Переписать во второй массив все отрицательные числа. Ввод с клавиатуры и вывод на экран. Чтение с файла и запись.

Программа:

.386

.model flat, stdcall

include C:\Users\VANO\Desktop\masm32\include\kernel32.inc 

include C:\Users\VANO\Desktop\masm32\include\windows.inc

include C:\Users\VANO\Desktop\masm32\include\user32.inc

includelib C:\Users\VANO\Desktop\masm32\lib\kernel32.lib

includelib C:\Users\VANO\Desktop\masm32\lib\user32.lib

bsize equ 128

nofdig equ 4

dsize equ 4

digz equ 10

fsize equ nofdig

.data

buf byte bsize dup(?)

b2 byte 0

masA dw bsize dup(10)

masB dw bsize dup(10)

masC dw bsize dup (10)

masD dw bsize dup (10)

fmt byte '%d',0

simw byte ?

fname byte "Massiv.txt" ,0

fname2 byte "Result.txt" ,0

fhandle dword ?

ps byte " ",13,10

xx dd 90

mes byte "Ìàññèâ çàïîëíåí" , 13,10

mes1 byte "Âûáîð îïåðàöèè:" , 13,10,"1.Ñîçäàòü ôàéë",13,10,"2.Îòêðûòü ôàéë",13,10,"3.Âûõîä",13,10

mes2 byte "Çàïîëíèòå ìàññèâ:", 13,10

mes3 byte "Ñîõðàíèòü ðåçóëüòàò?" , 13,10,"1.Äà",13,10,"2.Íåò",13,10

mes4 byte "Îòðèöàòåëüíûå ÷èñëà:", 13,10

mes5 byte "Ìàññèâ:", 13,10

d2s byte digz dup (?)

del dw 10

adr dd ?

a dw 0

a2 dw 0

ww dw 10

chet dw 0

minus dw 02Dh

over dw 040h

rf dword 0

cread dword ?

cwrite dword ?

stdin dword ?

stdout dword ?

.code

start:

invoke CharToOem,addr mes,addr mes

invoke CharToOem,addr mes5,addr mes5

invoke GetStdHandle,STD_OUTPUT_HANDLE

mov stdout, eax

invoke GetStdHandle,STD_INPUT_HANDLE

mov stdin, eax

Priv proc

invoke WriteConsole,stdout,addr mes1,58,addr cwrite, NULL

invoke ReadConsole,stdin,addr b2,2,addr cread,NULL

cmp b2,49

jz read

cmp b2,50

jz ofile

cmp b2,51

jz out1

jmp out1

Priv endp

ofile proc

invoke CreateFile,addr fname,GENERIC_READ,0, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0

mov fhandle,eax

invoke ReadFile,fhandle,addr masA,bsize, addr cread, NULL

invoke CloseHandle,fhandle

invoke WriteConsole,stdout,addr mes5,9,addr cwrite, NULL

lea esi, [masA]          

xor eax, eax

  rn2:

  mov ebx,0

  mov bl, byte ptr [esi]

  inc esi

  cmp bl, 58

  ja ex2

  cmp bl,47

  jb as2

mov simw, bl

invoke WriteConsole,stdout,addr simw,1,addr cwrite, NULL

  jmp rn2

  as2:

  cmp bl, 13

  jne ex2

mov simw, 02ch

invoke WriteConsole,stdout,addr simw,1,addr cwrite, NULL

add edi,4

   xor eax,eax

  ex2:

  cmp bl,040h

  jne rn2

  mov adr, 0

  invoke Beep,440,25

  invoke WriteConsole,stdout, addr ps, 3, addr cwrite,NULL

jmp crt

ofile endp

read proc

mov cread,0

invoke WriteConsole,stdout,addr mes2,19,addr cwrite, NULL

lea ebx, buf

lea esi, masA

cr:

invoke ReadConsole,stdin,addr buf,bsize,addr cread,NULL

cmp cread, 2

jz ro

mov eax,[ebx]

mov [esi], eax

add esi,4

jmp cr

ro:

mov eax,040h

mov [esi], eax

invoke CreateFile,addr fname,GENERIC_WRITE,0, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0

mov fhandle , eax

invoke WriteFile,fhandle, addr masA,bsize, addr cwrite, NULL

invoke CloseHandle, fhandle

read endp

invoke WriteConsole,stdout,addr mes,17,addr cwrite, NULL

crt proc

lea esi, [masA]          

lea edi, [masB]

xor eax, eax

xor edx, edx

  rn:

  mov ebx,0

  mov bl, byte ptr [esi]

  inc esi

  cmp bl ,02dh

  jnz ss3

mov chet,1

jmp rn

  ss3:

  cmp bl, 58

  ja ex

  cmp bl,47

  jb as

  sub bl,30h

  mul ww

  add eax, ebx

  dec(rf)

  jmp rn

  as:

  cmp bl, 13

  jne ex

  cmp chet ,1

  jne ss4

  neg eax

  mov chet,0

  ss4:

   mov [edi], eax

   add edi,4

   xor eax,eax

   xor edx,edx

  ex:

  cmp bl,040h

  jne rn

  mov adr, 0

  mov eax,040h

  mov [edi], eax

  add edi,4

  invoke Beep,440,25

 crt endp

scan proc

lea esi, masB

lea edi, masC

s1:

mov eax, [esi]

cmp eax, 040h

jz s3

test eax,eax

js negativ

add esi,4

jmp s1

negativ:

neg eax

mov [edi],eax

add esi,4

add edi,4

jmp s1

s3:

mov eax, 040h

mov [edi], eax

invoke Beep,400,25

invoke WriteConsole,stdout, addr mes4, 22, addr cwrite,NULL

scan endp

preout proc

lea esi,masC

lea edi, masD

st1:

mov eax, 040h

            cmp [esi], eax

            je ext

invoke WriteConsole,stdout, addr minus, 1, addr cwrite,NULL

mov eax, [esi]

push    -1        

l:         xor edx,edx   

            div       del      

            push edx

            cmp     eax,0  

            jne       l          

l2:       pop      edx     

            cmp     edx,-1 

            je         ex

            add edx, '0'

mov [edi], edx

    invoke WriteConsole,stdout, addr [edi], 1, addr cwrite,NULL

            inc(edi)

            jmp     l2        

            ex:

            add esi,4

    mov eax, 02Ch

    add [edi], eax

    invoke WriteConsole,stdout, addr [edi], 1, addr cwrite,NULL

    inc(edi)

            jmp st1

            ext:

invoke WriteConsole,stdout, addr ps, 3, addr cwrite,NULL

invoke WriteConsole,stdout,addr mes3,35,addr cwrite, NULL

m:

invoke ReadConsole,stdin,addr buf,4,addr cread,NULL

cmp buf,49

jz sf

cmp buf,50

jz out1

cmp cread, 2

jz out1

jmp m

sf:

invoke CreateFile,addr fname2,GENERIC_WRITE,0, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0

mov fhandle , eax

invoke WriteFile,fhandle, addr masD,bsize, addr cwrite, NULL

invoke CloseHandle, fhandle

invoke Beep,420,12

preout endp

out1:

invoke ExitProcess,0

end start

Похожие материалы

Информация о работе