x86-16 machine code, 2 bytes
As @CodyGray correctly points out, taking input as a string and output to a register removes the bulk of the standalone program version.
Input string is in SI
, length in CX
and output character is in AL
:
F3 AC REPZ LODSB ; start at memory location pointer in SI, put next value in AL,
; loop CX number of times. The last char will be in AL when done.
Or 4 bytes as a "Pascal string" (length is prepended to beginning of string):
AC LODSB ; first byte is string length
91 XCHG AX, CX ; move length to CX for loop
F3 AC REPZ LODSB ; start at memory location pointer in SI, put next value in AL,
; loop CX number of times. The last char will be in AL when done.
Or 5 bytes as a "C string" (zero/null terminated), input in DI
:
F2 AE REPNZ SCASB ; scan for value in AL (0), end when found and advance DI
8A 45 FE MOV AL, [DI-2] ; DI is now two bytes ahead of last, put value of DI-2 into AL
x86-16 machine code, IBM PC DOS, 12 11 10 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
B3 80 MOV BL, 80H ; BX to DOS PSP at 80H
8A 07 MOV AL, BYTE PTR[BX] ; get command line tail length
D7 XLAT ; AL = [BX+AL]
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:
