Lab 1: Основы ассемблера #1

Open
ElectronixTM wants to merge 13 commits from labs/01 into main
5 changed files with 390 additions and 0 deletions
Showing only changes of commit 6c9d810c6e - Show all commits

View File

@ -46,12 +46,21 @@ int main(void) {
set_input_mode(); set_input_mode();
while (isKeyPressed() == 0) { while (isKeyPressed() == 0) {
asm { // asm {
push ax // push ax
in al,0x40 // in al,0x40
} // }
unsigned char Tmm = _AL;
asm pop ax unsigned char Tmm = 0;
asm (
"push rax\n\t"
"in al, 0x40"
"mov %0, al"
"pop rax"
:"=r"(Tmm)
:
:"rax"
);
delay(500); delay(500);
printf("\n Порт40 = %d", Tmm); printf("\n Порт40 = %d", Tmm);
} }
@ -69,46 +78,58 @@ int main(void) {
reset_input_mode(); reset_input_mode();
system("pause"); system("pause");
int Time; // Данная секция закомментирована, поскльку линукс не дает обратиться к
set_input_mode(); // не промапанной и не аллоцированной памяти. Но даже если ее аллоцировать
while (isKeyPressed() == 0) { // mmem'ом, все равно эта память будет виртуальная, поэтому смысла делать
asm push ds // это не имеет. Вариант просмотра содержимого условной ячейки памяти на nasm
asm push si // приведен в файле time.asm. Объяснить тот код, который я вижу
asm mov ax, 40h // на базовом уровне я в состоянии
asm mov ds, ax
asm mov si, 0x6C
asm mov ax, [ds : si]
asm mov Time, ax
asm pop si
asm pop ds
printf("\n %d", Time); // int Time;
delay(300); // set_input_mode();
} // while (isKeyPressed() == 0) {
reset_input_mode(); // Здесь происходит операция получения времени суток при
// помощи обращения к специально размеченой области памяти
// Однако можно ли такой фокус сделать в linux это еще надо узнать
// asm push ds
// asm push si
// asm mov ax, 40h
// asm mov ds, ax
// asm mov si, 0x6C
// asm mov ax, [ds : si]
// asm mov Time, ax
// asm pop si
// asm pop ds
// asm(
// "mov "
// );
//
// printf("\n %d", Time);
// delay(300);
// }
// reset_input_mode();
//
// beep(400, 200);
// for (lCnt = 0; lCnt < 1000000; lCnt++) {
// a1:
// asm {
// mov ax,iA
// mov ax,iA
// mov ax,iA
// mov ax,iA
// mov ax,iA
// mov ax,iA
// mov ax,iA
// mov ax,iA
// mov ax,iA
// a2:
// mov ax,iA
// }
// }
// beep(400, 200);
beep(400, 200); // здесь секция для выполнения замеров времени. Поскольку доступ к звуку
for (lCnt = 0; lCnt < 1000000; lCnt++) { // Я иметь не могу, если не буду использовать pulseaudio, замерим старыми дедовскими методами
a1: // При помощи clock_gettime
asm {
mov ax,iA
mov ax,iA
mov ax,iA
mov ax,iA
mov ax,iA
mov ax,iA
mov ax,iA
mov ax,iA
mov ax,iA
a2:
mov ax,iA
}
}
beep(400, 200);
} }
//void beep(unsigned iTone, unsigned iDlit) {
// sound(iTone);
// delay(iDlit);
// nosound();
//}

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <termios.h> #include <termios.h>
#include <time.h>
/* Use this variable to remember original terminal attributes. */ /* Use this variable to remember original terminal attributes. */
@ -32,7 +33,8 @@ void set_input_mode()
/* Set the funny terminal modes. */ /* Set the funny terminal modes. */
tcgetattr (STDIN_FILENO, &tattr); tcgetattr (STDIN_FILENO, &tattr);
tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
tattr.c_cc[VMIN] = 1; tattr.c_cc[VMIN] = 0;
tattr.c_cc[VTIME] = 0;
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr); tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
} }
@ -52,10 +54,10 @@ char isKeyPressed()
return 0; return 0;
} }
//int main() int main()
//{ {
// set_input_mode(); set_input_mode();
// while (isKeyPressed() == 0) {} while (isKeyPressed() == 0) {printf("hell\n");}
// printf("ok"); printf("ok\n");
// reset_input_mode(); reset_input_mode();
//} }