School Commit Init
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
;Read a string of unsigned numbers in base 10 from keyboard.
|
||||
;Determine the maximum value of the string and write it in the file
|
||||
;max.txt (it will be created) in 16 base.
|
||||
|
||||
bits 32
|
||||
|
||||
global start
|
||||
|
||||
extern exit,printf,scanf
|
||||
import exit msvcrt.dll
|
||||
import printf msvcrt.dll
|
||||
import scanf msvcrt.dll
|
||||
|
||||
%include "subprogram.asm"
|
||||
%include "writefile.asm"
|
||||
|
||||
segment data use32 class=data
|
||||
dd 0
|
||||
read_format db "%100[0-9a-zA-Z ]",0
|
||||
write_format db "%X",0
|
||||
text_file db "text_file.txt",0
|
||||
mode db "w",0
|
||||
string times 101 db 0
|
||||
max resd 1
|
||||
|
||||
segment code use32 class=code
|
||||
start:
|
||||
push dword string
|
||||
push dword read_format
|
||||
call [scanf]
|
||||
add ESP,4*2
|
||||
push dword max
|
||||
push dword string
|
||||
call get_max
|
||||
add ESP,4*2
|
||||
push dword write_format
|
||||
push EAX
|
||||
push dword mode
|
||||
push dword text_file
|
||||
call write_to_file
|
||||
add ESP, 4*2
|
||||
push dword 0
|
||||
call [exit]
|
||||
@@ -0,0 +1,38 @@
|
||||
%ifndef _SUBPROGRAM_ASM_
|
||||
%define _SUBPROGRAM_ASM_
|
||||
|
||||
table db ""
|
||||
maximum dd 0
|
||||
|
||||
get_max:
|
||||
mov ESI,[ESP+4]
|
||||
begin:
|
||||
mov ECX,0
|
||||
loop_label:
|
||||
lodsb
|
||||
cmp AL,' '
|
||||
je eon
|
||||
cmp AL,0
|
||||
je zero
|
||||
sub AL,"0"
|
||||
mov EBX,0
|
||||
mov BL,AL
|
||||
mov EAX,ECX
|
||||
mov EDX,10
|
||||
mul EDX
|
||||
add EAX,EBX
|
||||
mov ECX,EAX
|
||||
jmp loop_label
|
||||
eon:
|
||||
cmp ECX,[maximum]
|
||||
jb begin
|
||||
mov [maximum],ECX
|
||||
jmp begin
|
||||
zero:
|
||||
cmp ECX,[maximum]
|
||||
jb ending
|
||||
mov [maximum],ECX
|
||||
ending:
|
||||
mov EAX,[maximum]
|
||||
ret
|
||||
%endif
|
||||
@@ -0,0 +1 @@
|
||||
41
|
||||
@@ -0,0 +1,28 @@
|
||||
%ifndef _WRITEFILE_ASM_
|
||||
%define _WRITEFILE_ASM_
|
||||
|
||||
extern fopen,fprintf,fclose
|
||||
import fopen msvcrt.dll
|
||||
import fprintf msvcrt.dll
|
||||
import fclose msvcrt.dll
|
||||
|
||||
write_to_file:
|
||||
mov EAX,[ESP+4*1]
|
||||
mov EBX,[ESP+4*2]
|
||||
push EBX
|
||||
push EAX
|
||||
call [fopen]
|
||||
add ESP,4*2
|
||||
mov ECX,[ESP+4*3]
|
||||
mov EDX,[ESP+4*4]
|
||||
push ECX
|
||||
push EDX
|
||||
push EAX
|
||||
call [fprintf]
|
||||
pop EAX
|
||||
add ESP,4*2
|
||||
push EAX
|
||||
call [fclose]
|
||||
add ESP,4*1
|
||||
ret
|
||||
%endif
|
||||
Reference in New Issue
Block a user