School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,36 @@
;An unsigned number a on 32 bits is given. Print the hexadecimal
;representation of a, but also the results of the circular permutations
;of its hex digits.
bits 32
global start
extern exit,printf
import exit msvcrt.dll
import printf msvcrt.dll
%include "subprogram.asm"
segment data use32 class=data
format db "%X ",0
a dd 12ABCDEFh
permutations resd 8
segment code use32 class=code
start:
push dword [a]
push dword permutations
call subprogram
add ESP,4*2
mov ECX,8
label:
push ECX
push dword [permutations+ECX*8]
push dword format
call [printf]
add ESP,4*2
pop ECX
loop label
push dword 0
call [exit]
@@ -0,0 +1,13 @@
%ifndef _SUBPROGRAM_ASM_
%define _SUBPROGRAM_ASM_
subprogram:
mov ECX,8
mov EBX,[ESP+4]
mov EAX,[ESP+8]
.label:
mov [EBX+ECX*8],EAX
rol EAX,4
loop .label
ret
%endif
@@ -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
@@ -0,0 +1,11 @@
#include<stdio.h>
void subprogram(int* p,int a);
int main(){
int a=0x12345678;
int p[8];
subprogram(p,a);
for (int i=7;i>=0;i--){
printf("%x ",p[i]);
}
return 0;
}
@@ -0,0 +1,13 @@
bits 32
global _subprogram
segment code use32 class=code public
_subprogram:
mov ECX,8
mov EBX,[ESP+4]
mov EAX,[ESP+8]
.label:
mov [EBX+ECX*4-4],EAX
rol EAX,4
loop .label
ret
@@ -0,0 +1,13 @@
#include<stdio.h>
void subprogram(char a[], int b[]);
int main(){
char a[]="10100111b01100011b110b101011b";
int b[]={0,0,0,0,0,0,0,0,0,0};
subprogram(a,b);
for (int i=0;b[i]!=0;i++){
printf("%d ",b[i]);
}
return 0;
}
@@ -0,0 +1,32 @@
bits 32
global _subprogram
segment code use32 class=code public
_subprogram:
cld
mov ESI,[ESP+4]
mov EDI,[ESP+8]
mov EAX,0
mov EBX,0
label:
lodsb
cmp byte AL,0
je end
cmp byte AL,'b'
jne skip
mov EAX,EBX
stosd
mov EBX,0
jmp label
skip:
sub AL,'0'
mov ECX,0
mov Cl,AL
mov EAX,EBX
mov EDX,2
mul EDX
mov EBX,EAX
add EBX,ECX
jmp label
end:
ret
@@ -0,0 +1,32 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 1
b db 2
c db 5
d db 1
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a]
add al, [d]
mov bl, [b]
add bl, [d]
sub [c],al
add bl,[c]
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,31 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b db 4
c db 3
d db 12
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a]
add al,13
sub al,[c]
add al,[d]
sub al,7
add al,[b]
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,31 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a dw 10
b dw 13
c dw 42
d dw 16
; our code starts here
segment code use32 class=code
start:
; ...
mov ax,[c]
add ax,[b]
add ax,[a]
mov bx,[d]
add bx,[d]
sub ax,bx
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,30 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a dw 10
b dw 31
c dw 13
d dw 10
; our code starts here
segment code use32 class=code
start:
; ...
mov ax,[a]
add ax,[b]
add ax,[b]
mov bx,[c]
sub bx,[d]
add ax,bx
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,35 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b db 12
c db 8
d dw 45
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a]
add al,[b]
sub al,[c]
mov bl,2
mul bl
add ax,[d]
sub ax,5
mov bx,[d]
mul bx
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,42 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b db 12
c db 5
d dw 45
; our code starts here
segment code use32 class=code
start:
; ...
mov ax,0
mov al,[a]
add al,[b]
mov bl,2
div bl
mov bl,al
mov ax,0
mov al,[a]
div byte [c]
mov cl,10
sub cl,al
add bl,cl
mov ax,0
mov al,[b]
mov cl,4
div cl
add bl,al
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,34 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b db 2
c db 16
d db 42
e dw 52
f dw 16
g dw 36
h dw 28
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a]
sub al,[b]
mov bl,4
mul bl
div byte [c]
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,34 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b db 25
c db 2
d db 64
e dw 25
f dw 17
g dw 85
h dw 19
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a]
mul al
mov bx,[e]
add bx,[f]
sub ax,bx
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,24 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
; our code starts here
segment code use32 class=code
start:
; ...
mov al,1
add al,9
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,25 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
; our code starts here
segment code use32 class=code
start:
; ...
mov al,4
mov bl,4
mul bl
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,38 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 12h
b dw 74A1h
c dd 243F2149h
d dq 768AC79B8296E852h
; our code starts here
segment code use32 class=code
start:
mov AL,[a] ;AL=a
cbw
cwde ;EAX=a
mov EBX,EAX ;EBX=a
mov AX,[b] ;AX=b
cwde ;EAX=b
add EAX,[c] ;EAX=c+b
add EAX,EBX ;EAX=c+b+a
cdq ;EDX:EAX=c+b+a
mov EBX,[d]
mov ECX,[d+4] ;ECX:EBX=d
add EBX,[d]
adc ECX,[d+4] ;ECX:EBX=d+d
sub EAX,EBX
sbb EDX,ECX ;EDX:EAX=(c+b+a)-(d+d)
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,38 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 12h
b dw 74A1h
c dd 243F2149h
d dq 768AC79B8296E852h
; our code starts here
segment code use32 class=code
start:
mov AL,[a] ;AL=a
cbw
cwde
cdq ;EDX:EAX=a
mov EBX,[d]
mov ECX,[d+4] ;ECX:EBX=d
sub EBX,EAX
sbb ECX,EDX ;ECX:EBX=d-a
sub EAX,[c] ;EAX=a-c
cdq
sub EBX,EAX
sbb ECX,EDX ;ECX:EBX=(d-a)-(a-c)
sub EBX,[d]
sbb ECX,[d+4] ;ECX:EBX=(d-a)-(a-c)-d
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,46 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 12h
b dw 74A1h
c dd 243F2149h
d dq 768AC79B8296E852h
; our code starts here
segment code use32 class=code
start:
mov EBX,0 ;EBX=0
mov BL,[a] ;EBX=a
mov EDX,[d+4] ;
mov EAX,[d] ;EDX:EAX=d
add EAX,EBX
adc EDX,0 ;EDX:EAX=a+d
mov EBX,[c]
mov ECX,0 ;ECX:EBX=c
sub EBX,EAX
sbb ECX,EDX ;ECX:EBX=c-(a+d)
push EBX
push ECX
mov EDX,[d+4]
mov EAX,[d] ;EDX:EAX=d
mov ECX,0
mov CX,[b] ;ECX=b
add EAX,ECX
adc EDX,0 ;EDX:EAX=b+d
pop ECX
pop EBX ;ECX:EBX=c-(a+d)
add EAX,EBX
adc EDX,ECX ;EDX:EAX=c-(a+d)+(b+d)
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,35 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 12h
b dw 74A1h
c dd 243F2149h
d dq 768AC79B8296E852h
; our code starts here
segment code use32 class=code
start:
; ...
mov EAX,0
mov EBX,0
mov AL,[a] ;EAX=a
mov BX,[b] ;EBX=b
add EBX,EAX ;EBX=b+a
mov ECX,[c] ;ECX=c
sub ECX,EAX ;ECX=c-a
sub ECX,EBX ;ECX=c-a-(b+a)
add ECX,[c] ;ECX=c-a-(b+a)+c
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,39 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 12h
b dd 7483AB72h
c dq 768AC79B8296E852h
; our code starts here
segment code use32 class=code
start:
mov AL,[a] ;AL=a
imul byte [a] ;AX=a*a
cwde ;EAX=a*a
sub EAX,[b] ;EAX=a*a-b
add EAX,7 ;EAX=a*a-b+7
push EAX
mov AL,[a] ;AL=a
cbw
cwde ;EAX=a
add EAX,2 ;EAX=2+a
mov EBX,EAX ;EBX=2+a
pop EAX ;EAX=a*a-b+7
cdq ;EDX:EAX=a*a-b+7
idiv EBX ;EAX=(a*a-b+7)/(2+a)
cdq ;EDX:EAX=(a*a-b+7)/(2+a)
add EAX,[c]
adc EDX,[c+4] ;EDX:EAX=c+(a*a-b+7)/(2+a)
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,58 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a dw 7293h
b db 0A8h
c dw 0B749h
d db 4Bh
e dd 7483AB72h
x dq 768AC79Bh
; our code starts here
segment code use32 class=code
start:
mov EAX,[x]
mov EDX,[x+4] ;EDX:EAX=x
mov EBX,2 ;EBX=2
idiv EBX ;EAX=x/2
push EAX
mov AL,[b] ;AL=b
cbw ;AX=b
mov BX,AX ;BX=b
pop EAX
add BX,[a] ;BX=a+b
mov ECX,EAX ;ECX=x/2
mov AX,100 ;AX=100
imul BX ;EAX=100*(a+b)
add ECX,EAX ;ECX=x/2+100*(a+b)
mov AX,3 ;AX=3
cwd ;DX:AX=3
push AX
mov AL,[d] ;AL=d
cbw ;AX=d
mov BX,AX ;BX=d
pop AX
add BX,[c] ;BX=c+d
idiv BX ;AX=3/(c+d)
cwde
sub ECX,EAX ;ECX=x/2+100*(a+b)-3/(c+d)
mov EAX,ECX
cdq
mov EBX,EDX
mov EAX,[e] ;EAX=e
imul dword [e] ;EDX:EAX=e*e
add EAX,ECX
adc EDX,EBX ;EDX:EAX=x/2+100*(a+b)-3/(c+d)+e*e
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,37 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 12h
b dd 7483AB72h
c dq 768AC79B8296E852h
; our code starts here
segment code use32 class=code
start:
mov AL,[a] ;AL=a
mul byte [a] ;AX=a*a
mov BX,AX
mov EAX,0
mov AX,BX ;EAX=a*a
sub EAX,[b] ;EAX=a*a-b
add EAX,7 ;EAX=a*a-b+7
mov EDX,0 ;EDX:EAX=a*a-b+7
mov EBX,0 ;EBX=0
mov BL,[a] ;EBX=a
add EBX,2 ;EBX=2+a
div EBX ;EAX=(a*a-b+7)/(2+a)
mov EDX,0 ;EDX:EAX=(a*a-b+7)/(2+a)
add EAX,[c]
adc EDX,[c+4] ;EDX:EAX=c+(a*a-b+7)/(2+a)
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,50 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a dw 7293h
b db 0A8h
c dw 0B749h
d db 4Bh
e dd 7483AB72h
x dq 768AC79Bh
; our code starts here
segment code use32 class=code
start:
mov EAX,[x]
mov EDX,[x+4] ;EDX:EAX=x
mov EBX,2 ;EBX=2
div EBX ;EAX=x/2
mov BX,0
mov BL,[b] ;BX=b
add BX,[a] ;BX=a+b
mov ECX,EAX ;ECX=x/2
mov AX,100 ;AX=100
mul BX ;EAX=100*(a+b)
add ECX,EAX ;ECX=x/2+100*(a+b)
mov AX,3 ;AX=3
mov DX,0 ;DX:AX=3
mov BX,0 ;BX=0
mov BL,[d] ;BX=d
add BX,[c] ;BX=c+d
div BX ;AX=3/(c+d)
mov EBX,0
mov BX,AX ;EBX=3/(c+d)
sub ECX,EBX ;ECX=x/2+100*(a+b)-3/(c+d)
mov EAX,[e] ;EAX=e
mul dword [e] ;EDX:EAX=e*e
add EAX,ECX
adc EDX,0 ;EDX:EAX=x/2+100*(a+b)-3/(c+d)+e*e
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,46 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 4Fh
b dw 8241h
c resd 1
; our code starts here
segment code use32 class=code
start:
mov ECX,0
mov CL,1111_1111b
mov EAX,0
mov AL,[a]
and AL,1111_0000b
shl EAX,4
or ECX,EAX
mov EBX,0
mov BX,[b]
and EBX, 0000_0011_1111_1100b
shl EBX,10
or ECX,EBX
mov EAX,0
mov AL,[a]
and AL,0000_1111b
shl EAX,20
or ECX,EAX
mov EAX,0
mov AL,[b+1]
ror EAX,8
or ECX,EAX
mov [c],ECX
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,42 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a dw 4A2Fh
b dw 8241h
c dw 931Dh
d resw 1
; our code starts here
segment code use32 class=code
start:
mov AX,[a]
and AX,0000_0000_0011_1110b
shr AX,1
mov BX,[b]
and BX,0000_0111_1100_0000b
shr BX,6
mov CX,[c]
and CX,1111_1000_0000_0000b
shr CX,11
mov DX,0
add DX,AX
add DX,BX
add DX,CX
mov [d],DX
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+50
View File
@@ -0,0 +1,50 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
;Given a byte string S of length l, obtain the string D of length l-1 as D(i) = S(i) * S(i+1) (each element of D is the product of two consecutive elements of S).
segment data use32 class=data
; ...
S db 1,2,3,4
l equ $-S
D resw l-1
; our code starts here
segment code use32 class=code
start:
; ...
; mov ECX,0
; jmp_label:
; mov AL,[S+ECX]
; mov BL,[S+ECX+1]
; imul BL
; mov [D+2*ECX],AX
; inc ECX
; cmp ECX,l-1
; jb jmp_label
mov ECX,l
mov ESI,0
jmp_label:
mov AL,[S+ESI]
mov BL,[S+ESI+1]
imul BL
mov [D+2*ESI],AX
inc ESI
loop jmp_label
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,46 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
;Two character strings S1 and S2 are given. Obtain the string D by concatenating the elements found on odd positions in S2 and the elements found on even positions in S1.
segment data use32 class=data
S1 db 'abcbef'
l1 equ $-S1
S2 db '123456'
l2 equ $-S2
D resb l1/2+l2/2+l2 % 2
; our code starts here
segment code use32 class=code
start:
; ...
mov EDI,0
mov ESI,0
S2_label:
mov AL,[S2+ESI]
mov [D+EDI],AL
inc EDI
add ESI,2
cmp ESI,l2
jb S2_label
mov ESI,0
S1_label:
mov AL,[S1+1+ESI*2]
mov [D+EDI],AL
inc ESI
inc EDI
cmp ESI,l1/2
jb S1_label
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+47
View File
@@ -0,0 +1,47 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a dd 127f5678h,0abcdabcdh
l equ $-$$
b resb l
; our code starts here
segment code use32 class=code
start:
; ...
mov ECX,l
mov ESI,a
mov EDI,b
CLD
label:
LODSB
cbw
mov BX,AX
LODSB
cbw
mov DX,AX
LODSB
cbw
add BX,AX
LODSB
cbw
add AX,DX
rol EAX,16
mov AX,BX
STOSD
sub ECX,4
jg label
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,59 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
s1 db 12h,78h
l1 equ $-s1
s2 db 34h,0ABh
l2 equ $-s2
s3 resb l1+l2
l3 equ $-s3
; our code starts here
segment code use32 class=code
start:
; ...
mov ECX,l3
mov ESI,0
mov EDX,0
mov EDI,s3
cld
label:
mov AL,0FFh
cmp ESI,l1
jge a
mov AL,[s1+ESI]
a:
mov BL,0FFh
cmp EDX,l1
jge b
mov BL,[s2+EDX]
b:
cmp AL,BL
jb less
mov AL,BL
inc EDX
STOSB
dec ECX
jmp comp
less:
inc ESI
dec ECX
STOSB
jmp comp
comp:
cmp ECX,0
jg label
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,51 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,scanf ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
import scanf msvcrt.dll
;Read two numbers a and b (in base 10) from the keyboard and calculate their product. This value will be stored in a variable called "result" (defined in the data segment).
segment data use32 class=data
query db "%d",0
a dd 0
b dd 0
result dq 0
; our code starts here
segment code use32 class=code
start:
; ...
push dword a
push dword query
call [scanf]
add ESP,4*2
push dword b
push dword query
call [scanf]
add ESP,4*2
mov EAX,[a]
imul dword [b]
mov [result],EAX
mov [result+4],EDX
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
msg="hey"
sleep(10)
s.sendto(str.encode(msg),("127.0.0.1",5555))
msg,adr=s.recvfrom(10)
print (msg.decode())
@@ -0,0 +1,47 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,scanf,printf ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
import scanf msvcrt.dll
import printf msvcrt.dll
; our data is declared here (the variables needed by our program)
;Read two numbers a and b (in base 10) from the keyboard. Calculate and print their arithmetic average in base 16
segment data use32 class=data
read_query db "%d",0
write_query db "The arithmetic average in base 16 is: 0x%08X",0
a dd 0
b dd 0
; our code starts here
segment code use32 class=code
start:
; ...
push dword a
push dword read_query
call [scanf]
add ESP,4*2
push dword b
push dword read_query
call [scanf]
add ESP,4*2
mov EAX,[a]
add EAX,[b]
sar EAX,1
push EAX
push write_query
call [printf]
add ESP, 4*2
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,72 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,fopen,fclose,printf,fread,strchr ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
import fopen msvcrt.dll
import fclose msvcrt.dll
import printf msvcrt.dll
import fread msvcrt.dll
import strchr msvcrt.dll
; our data is declared here (the variables needed by our program)
;A text file is given. Read the content of the file, count the number of vowels and display the result on the screen. The name of text file is defined in the data segment.
segment data use32 class=data
; ...
file_path db "text.txt",0
access_mode db "r",0
vowels db "aeiouAEIOU",0
message db "The number of vowels in the file is: %d",0
file dd 0
a db 0
count dd 0
; our code starts here
segment code use32 class=code
start:
; ...
push dword access_mode
push dword file_path
call [fopen]
add ESP,4*2
cmp EAX,0
jz end
mov [file],EAX
push dword [file]
push dword 1
push dword 1
push dword a
loop_label:
call [fread]
cmp EAX,0
jz done
push dword [a]
push dword vowels
call [strchr]
add ESP,4*2
cmp EAX,0
jz loop_label
inc dword [count]
jmp loop_label
done:
add ESP,4*4
; exit(0)
push dword [file]
call [fclose]
add ESP,4*1
push dword [count]
push dword message
call [printf]
add ESP,4*2
end:
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,86 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,fopen,fclose,printf,fread ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
import fopen msvcrt.dll
import fclose msvcrt.dll
import printf msvcrt.dll
import fread msvcrt.dll
; our data is declared here (the variables needed by our program)
;A text file is given. Read the content of the file, count the number of letters 'y' and 'z' and display the values on the screen. The file name is defined in the data segment.
segment data use32 class=data
; ...
file_path db "text.txt",0
access_mode db "r",0
message db `The number of 'y' in the file is: %d\nThe number of 'z' in the file is: %d`,0
file dd 0
a db 0
count_y dd 0
count_z dd 0
; our code starts here
segment code use32 class=code
start:
; ...
push dword access_mode
push dword file_path
call [fopen]
add ESP,4*2
cmp EAX,0
jz end
mov [file],EAX
push dword [file]
push dword 1
push dword 1
push dword a
loop_label:
call [fread]
cmp EAX,0
jz done
cmp byte [a],"y"
jz inc_y
cmp byte [a],"Y"
jz inc_y
cmp byte [a],"z"
jz inc_z
cmp byte [a],"Z"
jz inc_z
jmp loop_label
inc_y:
inc dword [count_y]
jmp loop_label
inc_z:
inc dword [count_z]
jmp loop_label
done:
add ESP,4*4
push dword [file]
call [fclose]
add ESP,4*1
push dword [count_z]
push dword [count_y]
push dword message
call [printf]
add ESP,4*3
end:
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1 @@
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee
@@ -0,0 +1 @@
abcD;aC#
@@ -0,0 +1,88 @@
;Se citesc dintr-un fisier caractere, pana la intalnirea caracterului
;#. Sa se afiseze la consola numarul literelor mici, urmat de numarul
;literelor mari citite.
bits 32
global start
extern exit,printf,fread,fopen,fclose
import exit msvcrt.dll
import printf msvcrt.dll
import fread msvcrt.dll
import fopen msvcrt.dll
import fclose msvcrt.dll
segment data use32 class=data
file_path db "file.txt",0
mode db "r",0
file resd 1
char resb 1
upcount dd 0
locount dd 0
upwrite db "The number of upper case letters: %d",10,13,0
lowrite db "The number of lower case letters: %d",10,13,0
segment code use32 class=code
start:
push dword mode
push dword file_path
call [fopen]
add esp,4*2
mov [file], EAX
cmp EAX,0
je error
loop_label:
push dword [file]
push dword 1
push dword 1
push dword char
call [fread]
add esp,4*4
cmp EAX,"0"
je end
cmp byte [char],"#"
je end
cmp byte [char],"A"
jl loop_label
cmp byte [char],"z"
jg loop_label
cmp byte [char],"Z"
jle upper
cmp byte [char],"a"
jge lower
jmp loop_label
upper:
inc dword [upcount]
jmp loop_label
lower:
inc dword [locount]
jmp loop_label
end:
push dword [file]
call [fclose]
add esp, 4*1
push dword [locount]
push dword lowrite
call [printf]
add esp,4*2
push dword [upcount]
push dword upwrite
call [printf]
add esp,4*2
error:
push dword 0
call [exit]
@@ -0,0 +1,30 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a db 2
b db 2
c db 3
d db 4
x resb 1
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a]
add al,[b]
mul byte [c]
div byte [d]
mov [x],al
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,36 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b db 2
c db 3
d db 4
x resb 1
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[b]
mul byte [c]
mov bl,[a]
mov bh,0
sub bx,ax
mov ax,bx
div byte [d]
mov [x],al
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,35 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b dw 2
c db 3
d db 4
x resw 1
; our code starts here
segment code use32 class=code
start:
; ...
mov ah,0
mov al,[a]
mul word [b]
mov bl,[d]
mov bh,0
div bx
mov bl,[c]
sub ax,bx
mov [x],ax
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,56 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 10
b dw 2
c dd 3
d db 4
f dw 1
g dw 2
x dq 2
; our code starts here
segment code use32 class=code
start:
; ...
mov al,[a] ;AL=a
cbw ;AX=a
imul word [b] ;DX:AX=a*b
push dx ;stack: dx,
push ax ;stack: dx,ax
mov al,[d] ;AL=d
cbw ;AX=d
cwde ;EAX=d
mov ecx,[c] ;ECX=c
sub ecx,eax ;ECX=c-d
pop eax ;EAX=a*b , stack:
cdq ;EDX:EAX=a*b
idiv dword ecx ;EAX=(a*b)/(c-d)
mov ecx,eax ;ECX=(a*b)/(c-d)
mov ax,[f] ;AX=f
imul word [g] ;DX:AX=f*g
push dx ;stack: DX
push ax ;stack: DX,AX
pop eax ;EAX=f*g , stack:
add eax,ecx ;EAX=(a*b)/(c-d)+f*g
cdq ;EDX:EAX=(a*b)/(c-d)+f*g
add [x],eax
adc [x+4],edx
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,44 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
a dd 1
b db 1
c dw 1
d dw 1
x resd 1
; our code starts here
segment code use32 class=code
start:
mov ax,[a] ;AX=a-low
mov dx,[a+2] ;DX=a-high DX:AX=a-low
mov bx,2 ;BX=2
idiv bx ;AX=a/2
mov dx,ax ;DX=a/2
mov al,[b] ;AL=b
mov bl,3 ;BL=3
imul bl ;AX=b*3
add dx,ax
mov ax,[c]
imul word [d]
push dx
push ax
pop eax
mov eax,ecx
mov ax,dx
cwde
sub eax,ecx
add eax,100
mov [x],eax
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,32 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 'message'
l equ $-a
b resb l
; our code starts here
segment code use32 class=code
start:
; ...
mov ESI,l
label:
mov AL,[a+ESI-1]
sub AL,'a'-'A'
mov [b+ESI-1],AL
dec ESI
jne label
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
@@ -0,0 +1,22 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
; our code starts here
segment code use32 class=code
start:
; ...
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+34
View File
@@ -0,0 +1,34 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db "coaie"
l equ $-$$
b resb l
; our code starts here
segment code use32 class=code
start:
; ...
mov ESI,a
mov EDI,b
mov ECX,l
cld
jecxz end
label:
lodsb
sub al,"a"-"A"
stosb
loop label
end:
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+36
View File
@@ -0,0 +1,36 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db "coaie"
l equ $-$$
b resb l
; our code starts here
segment code use32 class=code
start:
; ...
mov ESI,a
mov EDI,a+2*l-1
mov ECX,l
jecxz end
label:
CLD
lodsb
STD
stosb
loop label
end:
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+29
View File
@@ -0,0 +1,29 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
s1 dw 1,10,32
l1 equ ($-s1)/2
s2 dw 0FF23h,0AF21h,0B25h
l2 equ ($-s2)/2
s resb l1+l2
e db 10
; our code starts here
segment code use32 class=code
start:
; ...
mov ax,256
mov bl,1
div bl
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+35
View File
@@ -0,0 +1,35 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,printf,scanf ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
import printf msvcrt.dll ; printf is a function that prints a string to the standard output. It is defined in msvcrt.dll
import scanf msvcrt.dll ; scanf is a function that reads a string from the standard input. It is defined in msvcrt.dll
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
message db "n=",0
n dd 0
read db "%d",0
; our code starts here
segment code use32 class=code
start:
; ...
;Write a programs that prints the message "n=" on the screen and then read from keyword the value for the signed number n
push dword message
call [printf]
add ESI,4*1
push dword n
push dword read
call [scanf]
add ESI,4*2
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+43
View File
@@ -0,0 +1,43 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,printf,scanf ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
import printf msvcrt.dll ; printf is a function that prints a formatted string to the standard output
import scanf msvcrt.dll ; scanf is a function that reads a formatted string from the standard input
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
read_number db "%d",0
a dd 0
b dd 0
message db "Sum=%d",0
; our code starts here
segment code use32 class=code
start:
; ...
; read a and b
push dword a
push dword read_number
call [scanf]
add esp, 4*2
push dword b
push dword read_number
call [scanf]
add esp, 4*2
;print out the sum
mov eax, [a]
add eax, [b]
push eax
push dword message
call [printf]
add esp, 4*2
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+100
View File
@@ -0,0 +1,100 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit,fopen,fprintf,fscanf,fread,fwrite,remove,rename,fclose
import exit msvcrt.dll ; exit is a function that terminates the program. It is defined in msvcrt.dll
import fopen msvcrt.dll ; fopen is a function that opens a file. It is defined in msvcrt.dll
import fprintf msvcrt.dll ; fprintf is a function that prints a formatted string to a file. It is defined in msvcrt.dll
import fscanf msvcrt.dll ; fscanf is a function that reads a formatted string from a file. It is defined in msvcrt.dll
import fread msvcrt.dll ; fread is a function that reads a block of data from a file. It is defined in msvcrt.dll
import fwrite msvcrt.dll ; fwrite is a function that writes a block of data to a file. It is defined in msvcrt.dll
import remove msvcrt.dll ; remove is a function that deletes a file. It is defined in msvcrt.dll
import rename msvcrt.dll ; rename is a function that renames a file. It is defined in msvcrt.dll
import fclose msvcrt.dll ; fclose is a function that closes a file. It is defined in msvcrt.dll
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
file_path_read db "a.txt", 0 ; the path to the file we want to open
file_path_write db "b.txt", 0 ; the path to the file we want to open
access_mode_read db "r", 0 ; the access mode we want to use when opening the file
access_mode_write db "w", 0 ; the access mode we want to use when opening the file
file_read dd 0 ; the file pointer returned by fopen
file_write dd 0 ; the file pointer returned by fopen
read_value dd 0 ; the value read from the file
; our code starts here
segment code use32 class=code
start:
; ...
; open the file
push dword access_mode_read ; push the parameter for fopen onto the stack
push dword file_path_read ; push the parameter for fopen onto the stack
call [fopen] ; call fopen to open the file
add esp, 4*2 ; remove the parameters from the stack
cmp eax, 0 ; compare the return value of fopen with 0
jz exit_label ; if fopen returned 0, then the file could not be opened, so we exit_label the program
mov [file_read], eax ; save the file pointer returned by fopen in the variable file
push dword access_mode_write ; push the parameter for fopen onto the stack
push dword file_path_write ; push the parameter for fopen onto the stack
call [fopen] ; call fopen to open the file
add esp, 4*2 ; remove the parameters from the stack
cmp eax, 0 ; compare the return value of fopen with 0
jz exit_label ; if fopen returned 0, then the file could not be opened, so we exit_label the program
mov [file_write], eax ; save the file pointer returned by fopen in the variable file
; read the file
loop_label:
push dword [file_read] ; push the parameter for fread onto the stack
push dword 1 ; push the parameter for fread onto the stack
push dword 1 ; push the parameter for fread onto the stack
push dword read_value ; push the parameter for fread onto the stack
call [fread] ; call fread to read the file
add esp, 4*4 ; remove the parameters from the stack
cmp eax, 0 ; compare the return value of fread with 0
jz end ; if fread returned 0, then the file could not be read, so we exit_label the program
inc byte [read_value] ; increment the value read from the file
push dword [file_write] ; push the parameter for fwrite onto the stack
push dword 1 ; push the parameter for fwrite onto the stack
push dword 1 ; push the parameter for fwrite onto the stack
push dword read_value ; push the parameter for fwrite onto the stack
call [fwrite] ; call fwrite to write the file
add esp, 4*4 ; remove the parameters from the stack
cmp eax, 0 ; compare the return value of fwrite with 0
jz exit_label ; if fwrite returned 0, then the file could not be written, so we exit_label the program
jmp loop_label
end:
; close the file
push dword [file_read] ; push the parameter for fclose onto the stack
call [fclose] ; call fclose to close the file
add esp, 4 ; remove the parameter from the stack
push dword [file_write] ; push the parameter for fclose onto the stack
call [fclose] ; call fclose to close the file
add esp, 4 ; remove the parameter from the stack
;remove a.txt file
push dword file_path_read ; push the parameter for remove onto the stack
call [remove] ; call remove to remove the file
add esp, 4 ; remove the parameter from the stack
;rename b.txt to a.txt
push dword file_path_read ; push the parameter for rename onto the stack
push dword file_path_write ; push the parameter for rename onto the stack
call [rename] ; call rename to rename the file
add esp, 4*2 ; remove the parameters from the stack
exit_label:
push dword 0 ; push the parameter for exit_label onto the stack
call [exit] ; call exit_label to terminate the program
+1
View File
@@ -0,0 +1 @@
efg
+26
View File
@@ -0,0 +1,26 @@
bits 32
global start
extern exit,function,printf
import exit msvcrt.dll
import printf msvcrt.dll
segment data use32 class=data
str1 db "hello ",0
str2 db "world",0
new_str resb 100
format db "%s",0
segment code use32 class=code
start:
push dword str1
push dword str2
push dword new_str
call function
add ESP,4*3
push dword new_str
push dword format
call [printf]
add ESP,4*2
push dword 0
call [exit]
@@ -0,0 +1,19 @@
bits 32
global function
segment code use32 class=code public
function:
mov esi, [esp+12]
mov edi, [esp+4]
loop1:
movsb
cmp [esi], byte 0
jne loop1
mov esi, [esp+8]
loop2:
movsb
cmp [esi], byte 0
jne loop2
mov [edi], byte 0
ret
+30
View File
@@ -0,0 +1,30 @@
bits 32
global start
extern sum,exit,printf,scanf
import exit msvcrt.dll
import printf msvcrt.dll
import scanf msvcrt.dll
segment data use32 class=data
format db "%u",0
n dd 0
result dd 0
segment code use32 class=code
start:
push dword n
push dword format
call [scanf]
add ESP,4*2
push dword result
push dword [n]
call sum
add ESP,4*2
push dword [result]
push dword format
call [printf]
add ESP,4*2
push dword 0
call [exit]
@@ -0,0 +1,20 @@
bits 32
global sum
segment code use32 class=code
sum:
mov EAX,[ESP+4]
mov EBX,0
mov ECX,10
loop1:
cmp eax,0
je end
mov EDX,0
div ECX
add EBX,EDX
jmp loop1
end:
mov EDX,[ESP+8]
mov [EDX],EBX
ret
+70
View File
@@ -0,0 +1,70 @@
bits 32
global start
extern exit, printf, scanf, fopen, fclose, fread
import exit msvcrt.dll
import printf msvcrt.dll
import scanf msvcrt.dll
import fopen msvcrt.dll
import fclose msvcrt.dll
import fread msvcrt.dll
segment data use32 class=data
format db "%X", 0
n dd 0
path db "textfile.txt", 0
mode db "r", 0
filehandle dd 0
s db 0
string resb 17
segment code use32 class=code
start:
push dword n
push dword format
call [scanf]
add esp, 4*2
push dword mode
push dword path
call [fopen]
add esp, 4*2
cmp eax, 0
jz end
mov [filehandle], eax
mov eax,0
mov ax, [n]
mov edi, string
loop_label:
push eax
push edi
push dword [filehandle]
push dword 1
push dword 1
push dword s
call [fread]
add esp, 4*3
cmp eax, 0
jz end
pop edi
pop eax
shr eax, 1
jnc loop_label
mov edx,[s]
mov [edi], edx
inc edi
jmp loop_label
end:
mov byte [edi], 0
push dword string
call [printf]
add esp, 4
push dword [filehandle]
call [fclose]
add esp, 4
push dword 0
call [exit]
@@ -0,0 +1 @@
0123456789abcdef
+25
View File
@@ -0,0 +1,25 @@
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
; ...
a db 255
b dd 100h
; our code starts here
segment code use32 class=code
start:
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program
+23
View File
@@ -0,0 +1,23 @@
; The code below will calculate the result of some arithmetic operations in the EAX register, save the value of the registers, then display the result value and restore the value of the registers.
bits 32
global start
; declare extern functions
extern exit, printf
import exit msvcrt.dll
import printf msvcrt.dll ; tell assembler function is found in library msvcrt.dll
segment data use32 class=data
segment code use32 class=code
start:
; will calculate 20 + 123 + 7 in EAX
mov al, 250>>4
mov al,0ffffh>>4
mov al,0efffh>>12
mov al,-1>>4
mov al,-1>>12
push dword 0 ; we place on stack parameter for exit
call [exit] ; call exit to end the program