Assembly language and addressing modes
도입됨
21:25
폰 노이만 아키텍처
역사 대부분 동안 기계는 하나의 작업만 수행했습니다. 직조기는 천을 짜고, 계산기는 더했습니다. 새로운 작업을 하게 하려면 재설계해야 했습니다. 그러다 기만적으로 간단한…이 등장했습니다.
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| instruction/ɪnˈstrʌkʃn/ | A command that tells the processor what action to perform. |
| initial orders | The first instructions used to start EDSAC and translate programs from paper tape. |
| paper tape | A long strip of paper used to store information for a computer to read. |
| assembler/əˈsemblə/ | 어셈블러 |
| mnemonic/nɪˈmɒnɪk/ | |
| bit patterns | Arrangements of binary digits that represent instructions or data in a computer. |
| instruction set/ɪnˈstrʌkʃn set/ | 명령어 집합 |
| machine code/məˈʃiːn kəʊd/ | 머신 코드 |
| Assembly language/əˈsemblɪ ˈlæŋɡwɪdʒ/ | The readable form. |
| processor/ˈprəʊsesə/ | The component that executes instructions and performs the operations of a computer or similar system. |
| architecture/ˈɑːkɪtektʃə/ | The design of a computer system, including its processor and instruction set. |
| operand/ˈɒpərænd/ | 연산자 |
| high-level language/haɪ ˈlevl ˈlæŋɡwɪdʒ/ | A programming language that expresses instructions using abstractions rather than machine-specific operations. |
| statement/ˈsteɪtmənt/ | A line of code that tells a program what to do. |
| opcode/ˈɒpkəʊd/ | opcodes |
| symbolic address | A name used in a program to represent a memory address. |
| Pass 1 | The first reading of assembly source code to record labels and their addresses. |
| source/sɔːs/ | The original program written by a programmer before translation into machine code. |
| symbol table/ˈsɪmbl ˈteɪbl/ | 기호표 |
| label/ˈleɪbl/ | 라벨 |
| address/əˈdres/ | An identifier specifying a location in memory or on a network. |
| Pass 2 | The second reading of assembly source code to produce machine code. |
| forward references/ˈfɔːwəd ˈrefrənsɪz/ | 전방 참조 |
| general-purpose register | A small storage place inside a processor used to hold data during operations. |
| accumulator/əˈkjuːmjʊleɪtə/ | A register used to hold intermediate arithmetic or logical results during processing. |
| index register/ˈɪndeks ˈredʒɪstə/ | A register that holds a value added to an address during indexed addressing. |
| denary/ˈdiːnəri/ | The base-ten number system, using the digits zero through nine. |
| binary/ˈbaɪnəri/ | A number system using base two, with the digits zero and one. |
| hexadecimal/ˌheksəˈdesɪml/ | A base-sixteen number system using digits zero to nine and letters A to F. |
| Data movement | Operations that move data between registers and memory or load values into registers. |
| Input and output | Operations that receive data from outside a computer or send data out. |
| Arithmetic/əˈrɪθmətɪk/ | Calculations with numbers, such as adding and subtracting. |
| Compare/kəmˈpeə/ | An operation that checks two values and records the result in a flag. |
| Jumps | Instructions that change which instruction the processor executes next. |
| Bit manipulation | Operations that change or test individual bits within a value. |
| memory location | A place in memory that holds data and has an address. |
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| addressing mode/əˈdresɪŋ məʊd/ | 주소 지정 방식 |
| immediate addressing/ɪˈmiːdɪət əˈdresɪŋ/ | 즉각 주소 지정 |
| direct addressing/daɪˈrekt əˈdresɪŋ/ | 직접 주소 지정 |
| indirect addressing/ɪndaɪˈrekt əˈdresɪŋ/ | 간접 주소 지정 |
| indexed addressing/ˈɪndekst əˈdresɪŋ/ | 인덱드 주소 지정 |
| effective address | The final memory address calculated by the processor to access an operand. |
| relative addressing/ˈrelətɪv əˈdresɪŋ/ | 상대 주소 지정 |
| offset/ˈɒfset/ | A value added to an address to find another memory location. |
| operand field | The part of an instruction that specifies an operand or helps locate it. |
| array/əˈreɪ/ | An indexed collection of elements arranged in one or more dimensions. |
| element/ˈelɪmənt/ | A substance made of atoms with the same proton number. |
| flag/flæɡ/ | A bit that records whether a particular condition or event has occurred. |
| conditional jump | An instruction that changes the next instruction only when a condition is met. |
| mask/mæsk/ | A pattern of bits used with logical operations to select, test, set or clear particular bits. |
스위치 줄에 있는 31가지 명령
- 1949년 캠브리지의 EDSAC 컴퓨터는 데이비드 위틀러가 작성한 '초기 명령(initial orders)'이라는 이름으로 스위치에 설정된 31개의 명령에서 부팅되었습니다.
- 그들의 전적인 업무는 A나 S와 같은 문자를 종이 테이프에서 읽어 기계가 실제로 이해하는 숫자로 변환하는 것이었습니다: 첫 번째 어셈블러입니다.
- 그 이후로 프로그래머들은 비트 패턴 대신 기호를 사용해 왔으며, 시험에서 사용하는 명령 세트 역시 바로 이로부터 파생되었습니다.
- 이 수업은 이 변환 과정, 수작업으로 프로그램을 추적하는 것, 그리고 명령이 데이터를 어디에 두고 있는지 명시하는 5가지 방법에 대해 다룹니다.
머신 코드 및 어셈블리 언어
- 프로세서는 머신 코드를 실행합니다: 특정 아키텍처에만 적용되는 비트 패턴이며, 각각 하나의 연산 코드와 피연산자입니다.
- 어셈블리 언어는 가독 가능한 형태입니다. 각 명령은
LDD,ADD또는JMP와 같은 **기호(mnemonic)**로 쓰이며, 각 어셈블리 명령은 정확히 하나의 머신 코드 명령으로 변환됩니다. - 어셈블러가 이를 번역합니다. 관계는 일대일이며, 이것이 어셈블리를 고수준 언어와 구별시키는 점입니다. 고수준 언어에서는 한 문장이 여러 명령으로 확장됩니다.

각 기호는 하나의 연산 코드가 되며, 각 기호 주소는 숫자가 됩니다

Assembly language is:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Assembly uses mnemonics and maps one-to-one to machine code; an assembler translates it.
2회 passes 어셈블러
- Pass 1은 소스 코드를 읽어서 **심볼 테이블(symbol table)**을 구축합니다:
LOOP:과 같은 **라벨(label)**이 나타날 때마다 주소를 기록합니다. 코드는 생성되지 않습니다. - Pass 2는 소스 코드를 다시 읽고 코드를 생성하며, 각 기호를 연산 코드로, 각 기호 주소를 심볼 테이블의 숫자로 교체합니다.
- 전방 참조(forward references) 때문에 두 번의 pass가 필요합니다:
JMP LOOP이LOOP:라인이 아직 보이기 전에 나올 수 있으므로, 첫 번째 pass에서는 주소를 알 수 없습니다.

What does pass 1 of a two-pass assembler do?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Pass 1 records where each label is (the symbol table); pass 2 then generates code, using the table to resolve label references.
Put the two-pass assembler's work in order.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Pass 1 finds all the labels first, so pass 2 can resolve even a jump to a label defined later.
Why does the assembler need two passes?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
A jump may target a label that appears later in the source; pass 1 finds all labels first so pass 2 can resolve them.
worked example: 2회 passes 적용하기
- 프로그램은 주소 100에서 시작합니다.
100 LDD COUNT
101 LOOP: DEC ACC
102 CMP #0
103 JPN LOOP
104 END
105 COUNT: 5
- Pass 1은 각 라인의 주소를 세하고 라벨을 기록합니다:
LOOP= 101,COUNT= 105. 다른 것은 적지 않습니다. - Pass 2는 라인별로 번역합니다.
LDD COUNT은 피연산자 105를 가진LDD의 연산 코드가 됩니다;JPN LOOP은 피연산자 101을 가진JPN의 연산 코드가 됩니다. Pass 1이 없으면 첫 번째 라인을 번역할 수 없습니다.
How a two-pass assembler works
Step through it. The assembler reads your code twice: pass 1 just finds where every label lives, so pass 2 can fill in the addresses — that is how a jump to a label defined 나중에 still works.
In the worked example, pass 1 records the label LOOP with the address ____ in the symbol table.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The program starts at 100, so the second line, LOOP: DEC ACC, occupies 101. COUNT, on the sixth line, is 105.
명령 세트
- 캠브리지의 명령어 세트에는 일반용 레지스터인 어큐뮬레이터 ACC, 인덱스 레지스터 IX가 하나씩 있다. 피연산자
#n는 데나리,Bn는 이_Handle,&n는 hex,<address>는 주소 번호 또는 라벨로 표시된다. - 데이터 이동:
LDM #n,LDD <address>,LDI <address>,LDX <address>,LDR #n,MOV IX,STO <address>. 입출력:IN,OUT. - 산술 연산:
ADD,SUB,INC,DEC. 비교:CMP,CMI. 점프:JMP무조건,JPE및JPN조건부. 비트 조작:AND,OR,XOR,LSL,LSR. 이후END. - "Instructions are grouped": name the groups and give one instruction from each.
Which of these are groups in the instruction set? Select 모든 that apply.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Data movement, input/output, arithmetic, compare, conditional and unconditional jumps, and bit manipulation. A spreadsheet is application software, far above this level.
worked example: 프로그램 추적하기
- ACC 및 프로그램이 사용하는 모든 메모리 위치를 위한 열이 있는 표를 그린 후,
END까지 라인별로 업데이트하십시오.
100 LDM #0
101 STO TOTAL
102 LDD TOTAL
103 ADD #5
104 STO TOTAL
105 LDD COUNT
106 DEC ACC
107 STO COUNT
108 CMP #0
109 JPN 102
110 END
111 TOTAL: 0
112 COUNT: 3
- Pass 1 of the loop: ACC 0 → 5 (TOTAL = 5), COUNT 3 → 2, compare not equal, jump. Pass 2: TOTAL = 10, COUNT = 1, jump. Pass 3: TOTAL = 15, COUNT = 0, compare equal, no jump,
END. - 최종 값: TOTAL = 15, COUNT = 0, ACC = 0. 값이 바뀔 때만 새로운 행을 쓰고, 비교는 절대 건너뛰지 마십시오.
In the traced program, what is the value of TOTAL when END is reached?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
The loop adds 5 to TOTAL once for each of the three passes: 5, 10, 15.
주소 지정 방식(Addressing modes)
- 주소 지정 방식은 프로세서가 피연산자를 찾는 방법을 설명합니다.
| 방식 | 피연산자의 위치 | 예시 |
|---|---|---|
| 즉각 주소 지정(immediate addressing) | 값이 명령 자체에 포함됨 | LDM #10이 10을 로드 |
| 직접 주소 지정(direct addressing) | 명령에 주소가 포함되어 있음; 그곳에 저장된 값을 사용함 | LDD 200이 200의 내용을 로드 |
| 간접 주소 지정(indirect addressing) | 주소가 또 다른 주소를 포함하며, 그것이 데이터를 포함함 | LDI 200 |
| 인덱스 주소 지정(indexed addressing) | 유효 주소 = 주어진 주소 + 인덱스 레지스터 | IX가 포함된 LDX 200 |
| 상대 주소 지정(relative addressing) | 주소가 현재 명령으로부터의 오프셋임 | 점프 |

같은 피연산자 필드, 네 가지 다른 의미

In immediate addressing (e.g. LDM #10), the operand is:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Immediate addressing uses the literal value in the instruction (here, 10).
Match each addressing mode to its meaning.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Immediate = value; direct = address of the value; indirect = address of an address; indexed = base + index.
worked example: 하나의 피연산자, 네 가지 답안
- 메모리: 위치 200에 300이, 위치 300에 7이, 위치 202에 9가 저장되어 있습니다. 인덱스 레지스터 IX는 2를 포함합니다.
LDM #200이 200을 ACC에 넣음: 즉각, 숫자 그 자체.LDD 200이 300을 ACC에 넣음: 직접, 200의 내용.LDI 200이 7을 ACC에 넣음: 간접, 200에 있는 주소의 내용.LDX 200이 IX를 200에 더하고 202의 내용을 로드: 9. 같은 피연산자가 네 가지 방식으로 쓰였으나 네 가지 다른 값.

인덱스 주소 지정이 존재하는 이유
- 배열은 연속된 위치들의 연속입니다. IX = 0, 1, 2, …인
LDX 200은 명령을 변경하지 않고 요소 0, 1, 2, …을 읽습니다. - 루프 패턴:
LDR #0로 인덱스를 0으로 초기화,LDX ARRAY로 요소를 가져오기, 작업 수행,INC IX로 길이와 비교,JPN로 되돌아가기. - 직접 주소를 사용하려면 각 요소마다 별도의 명령어에 필요한 반면, 인덱스 주소는 하나면 충분함.

Indexed addressing is most useful for:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The effective address is base address + index register, so increasing the index walks through an array.
비교 및 점프
CMP #n또는CMP <address>는 ACC와 값을 비교하여 플래그를 설정합니다. ACC는 변경되지 않습니다.JPE <address>은 마지막 비교에서 값이 같을 때 점프함;JPN <address>은 값이 다를 때 점프함;JMP <address>은 항상 점프함.- 고수준 언어의
IF은CMP과 조건부 점프로 변환되며, 루프는 비교 후 라벨로 되돌아가는 점프로 구현됨.

CMP #0 changes the value held in the accumulator.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
A compare only sets the flag that the next conditional jump reads. The ACC is unchanged, which is why the trace shows no new ACC value on a CMP line.
놓칠 수 있는 점
LDM #10은 숫자 10을 로드함;LDD 10은 위치 10의 내용을 로드함.#이 전체 차이임.#은 십진수,B은 이_Handle数,&는 HEXADecimal입니다.AND &0F과AND B00001111는 동일한 마스크이며,AND #15도 마찬가지입니다.CMP은 ACC를 건드리지 않고 오직 플래그만 설정함.JPN은 값이 다를 때 점프함.- 어셈블러의 1차 pass는 코드를 생성하지 않음. 출력물은 기호 표이고, 전방 참조가 그 존재 이유임.
이해했습니다
- 기계어는 비트 패턴이고, 汇编은 일대일 대응되는 비유식(mnemonics)이며, 어셈블러를 통해 변환됨
- 두 번의 pass: 1차 pass는 라벨 주소의 기호 표를 구성하고, 2차 pass는 코드를 생성함; 전방 참조를 위해 필요함
- 트레이싱은 ACC와 모든 위치의 표를 한 줄씩 변경사항별로 기록함; CMP이 플래그를 설정하고, JPE/JPN이 이를 읽음
- 주소 지정 방식: 즉시
#n값 · 직접 주소의 내용 · 간접 주소의 주소 · 인덱스 주소 + IX (배열) · 상대 오프셋
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.