English 中文(简体)
• 计算主要压力的数量
原标题:how did i do it in my exam :) counting the number of keypresses

i 在今天的考试中提出这个问题,我为这个问题写了某些法典。 我要告诉我,哪里确实错了。

Problem: for an 8086 microprocessor,write code that does the following task. it asks for user to enter the data and it counts the keypresses..
on execution of the ALP,the first message is obtained "counting keypresses , press escape to stop." (without quotation marks) , if the user enters the escape, the second message "counting keypresses" is shown and the result of the count is stored in BX and shown in displayed in binary. also the keys pressed (while entering data) ,the input key shall be echoed in the next line.

Solution: (that i wrote)
.model tiny
.data
text1 db "counting keypresses,press escape to stop $"
text2 db "counting keypresses"
.code
.startup
mov dx,offset text1 ;displaying text1 (i guess so) mov ah,09h
int 21h
and bx,00h
label1 mov ah,01h ;(getting input from user and incrementing bx on every click) int 21h
inc bx
cmp al,1bh ;comparing with escape np label1
mov dx,offset text2 ;if zero then do this i.e display text2 mov ah,09h
int 21h
mov dx,offset bx ;display bx mov ah,09h
int 21h
.exit
end

i am not sure if the comments i added are suitable or not. i know my code wont be correct,infact it wont be correct at all,but i managed to write this on the basis of my one night preparation.so if anyone could tell me,what wrong i am doing,then i will be highly thankful. because i really need to perform well in the next exam.

最佳回答

你有基本的想法,但有一些细节。

首先,请:

cmp al, 1bh
np label1

我不敢确定什么是<代码>np。 您所希望的指示很可能有jnz 标签1。 如果<代码>,则这一条将适用。 Z 旗帜不定,意思是用户打上新闻社。

阁下有以下几个方面:

mov dx,offset bx ;display bx
mov ah,09h
int 21h

这不会奏效。 事实上,这本表无法汇编,因为你可以不占用登记册。 你们需要将BX的价值存储在记忆中,然后将这一记忆地址传给产出功能。 因此界定了贵国数据领域的2倍价值:

count dw 0  ; counter for output
      db  $  ; terminate output

Then you can write:

move [count],bx
mov dx, offset count
mov ah, 09h
int 21h

You did say that you want to output the count in binary, but I m not sure you know the ramifications of that. If the user presses only two keys, the output will be a binary 0 and a binary 2, which might display as boxes, or nothing at all, or perhaps funky characters. I don t remember how the int21 functions interpret all the control characters. For sure, though, if the user presses 13 keys, all you re going to get is a carriage return. And if the user presses 36 characters, the output will be ... nothing. Because 36 is the ASCII code for $ , and that s the output terminator character.

If you want to do a better job of output, you ll need to convert the value in BX to hexadecimal or decimal (hex is easier) to ASCII characters, and output those. I don t have a sample at hand.

最后,我不回顾《公约》规定21项职能是保存登记册。 BX是否在整个电话中保存? 如果没有的话,请在打电话之前使用<代码>push bx;在接获时,则需要<代码>pop bx。 否则,你们的计票将“不明确”。

问题回答

暂无回答




相关问题
How can I do a CPU cache flush in x86 Windows?

I am interested in forcing a CPU cache flush in Windows (for benchmarking reasons, I want to emulate starting with no data in CPU cache), preferably a basic C implementation or Win32 call. Is there a ...

What are the names of the new X86_64 processors registers?

Where can I find the names of the new registers for assembly on this architecture? I am referring to registers in X86 like EAX, ESP, EBX, etc. But I d like them in 64bit. I don t think they are the ...

How do I disassemble raw 16-bit x86 machine code?

I d like to disassemble the MBR (first 512 bytes) of a bootable x86 disk that I have. I have copied the MBR to a file using dd if=/dev/my-device of=mbr bs=512 count=1 Any suggestions for a Linux ...

32bit application access to 64bit registry

I have an OS Shell written in 32bit that is replacing the Explorer.exe of a Vista machine. I run a utility which is also written in 32bit, which allows to switch between the Explorer shell and My ...

Left Shift Overflow on 68k/x86?

I heard that the Motorola 68000 and Intel x86 architectures handle overflow from left shifting differently. Specifically the 68k LSL vs. the Intel SAL/SHL assembly instructions. Does anyone know the ...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签