Compare commits
5 Commits
main
...
4c423c7acc
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c423c7acc | |||
| a338ac968e | |||
| 386c7be1a7 | |||
| 34d0c33e87 | |||
| 65d5c3f5c3 |
109
01-asm-basics/main.c
Normal file
109
01-asm-basics/main.c
Normal file
@ -0,0 +1,109 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "substitutions.h"
|
||||
|
||||
#define PortCan0 0x40
|
||||
|
||||
void beep(unsigned iTone, unsigned iDlit);
|
||||
|
||||
void delay(unsigned int ms)
|
||||
{
|
||||
usleep(ms * 1000);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
long int lCnt = 0;
|
||||
int iA = 0x1234;
|
||||
|
||||
char *pT = (char *)0x46C;
|
||||
printf("\nПечатаем 10 раз значение байта с известным адресом\n");
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
printf(" \n %d ", *pT);
|
||||
}
|
||||
printf("\n Для продолжения нажмите любую клавишу \n");
|
||||
system("pause"); // Ждем нажатия клавиши
|
||||
|
||||
printf("\n Читаем содержимое порта с адресом 40 с помощью функции Си \n");
|
||||
printf("\n Для выхода из цикла - нажмите любую клавишу \n");
|
||||
|
||||
set_input_mode();
|
||||
while (isKeyPressed() == 0) {
|
||||
printf("\n Порт40 = %d", inp(PortCan0));
|
||||
delay(500);
|
||||
}
|
||||
reset_input_mode();
|
||||
|
||||
system("pause");
|
||||
printf("\n Читаем содержимое порта с адресом 40 ассемблером \n");
|
||||
|
||||
set_input_mode();
|
||||
while (isKeyPressed() == 0) {
|
||||
asm {
|
||||
push ax
|
||||
in al,0x40
|
||||
}
|
||||
unsigned char Tmm = _AL;
|
||||
asm pop ax
|
||||
delay(500);
|
||||
printf("\n Порт40 = %d", Tmm);
|
||||
}
|
||||
reset_input_mode();
|
||||
system("pause");
|
||||
printf("\n Для продолжения - нажмите любую клавишу \n");
|
||||
system("pause");
|
||||
|
||||
long *pTime = (long *)0x46C;
|
||||
set_input_mode();
|
||||
while (isKeyPressed() == 0) {
|
||||
printf("\n %ld", *pTime);
|
||||
delay(1000);
|
||||
}
|
||||
reset_input_mode();
|
||||
system("pause");
|
||||
|
||||
int Time;
|
||||
set_input_mode();
|
||||
while (isKeyPressed() == 0) {
|
||||
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
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void beep(unsigned iTone, unsigned iDlit) {
|
||||
sound(iTone);
|
||||
delay(iDlit);
|
||||
nosound();
|
||||
}
|
||||
61
01-asm-basics/substitutions.c
Normal file
61
01-asm-basics/substitutions.c
Normal file
@ -0,0 +1,61 @@
|
||||
#include "substitutions.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
|
||||
/* Use this variable to remember original terminal attributes. */
|
||||
|
||||
struct termios saved_attributes;
|
||||
|
||||
void reset_input_mode()
|
||||
{
|
||||
tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes);
|
||||
}
|
||||
|
||||
void set_input_mode()
|
||||
{
|
||||
struct termios tattr;
|
||||
char *name;
|
||||
|
||||
/* Make sure stdin is a terminal. */
|
||||
if (!isatty (STDIN_FILENO))
|
||||
{
|
||||
fprintf (stderr, "Not a terminal.\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Save the terminal attributes so we can restore them later. */
|
||||
tcgetattr (STDIN_FILENO, &saved_attributes);
|
||||
atexit (reset_input_mode);
|
||||
|
||||
/* Set the funny terminal modes. */
|
||||
tcgetattr (STDIN_FILENO, &tattr);
|
||||
tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
|
||||
tattr.c_cc[VMIN] = 1;
|
||||
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
|
||||
}
|
||||
|
||||
void delay(unsigned int ms)
|
||||
{
|
||||
usleep(ms * 1000);
|
||||
}
|
||||
|
||||
char isKeyPressed()
|
||||
{
|
||||
char key_handler = 0;
|
||||
read(STDIN_FILENO, &key_handler, 1);
|
||||
if (key_handler > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//int main()
|
||||
//{
|
||||
// set_input_mode();
|
||||
// while (isKeyPressed() == 0) {}
|
||||
// printf("ok");
|
||||
// reset_input_mode();
|
||||
//}
|
||||
9
01-asm-basics/substitutions.h
Normal file
9
01-asm-basics/substitutions.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef SUBSTITUTIONS_H
|
||||
#define SUBSTITUTIONS_H
|
||||
|
||||
void reset_input_mode();
|
||||
void set_input_mode();
|
||||
void delay(unsigned int ms);
|
||||
char isKeyPressed();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user