Files
solutions/01-asm-basics/main.c

115 lines
2.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <sys/io.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");
// Линуксу не сильно нравится, что ты насилуешь порты ввода и вывода процессора, поэтому нужно выдать ему на это дело разрешение
ioperm(PortCan0, 1, 3); // Что означает тройка напишу позже
set_input_mode();
while (isKeyPressed() == 0) {
printf("\n Порт40 = %d", inb(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();
//}